Skip to content

Commit 49bb431

Browse files
committed
Change default attachedOutputs to include classes and test-classes
Previously, when attachedOutputs was not specified in maven-build-cache-config.xml, the build cache would return an empty list, meaning no directories were cached by default. This caused issues where compiled classes were not restored from cache, leading to build failures or inconsistent behavior. Changes: - Modified CacheConfigImpl.getAttachedOutputs() to return a default list containing 'classes' and 'test-classes' directories when attachedOutputs is not configured - Added getDefaultAttachedOutputs() helper method to create the default configuration - Updated usage.md to reflect that classes and test-classes are now restored by default - Updated build-cache-config.mdo documentation to document the new default behavior This change addresses user reports in issues apache#259 and apache#340 where builds failed after cache restoration due to missing compiled classes. It also aligns with user expectations from PR apache#177 discussion where this default was requested. Fixes: apache#259, apache#340 Related: apache#177
1 parent 10eb2c4 commit 49bb431

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,24 @@ public String getLocalRepositoryLocation() {
575575
public List<DirName> getAttachedOutputs() {
576576
checkInitializedState();
577577
final AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs();
578-
return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirNames();
578+
if (attachedOutputs == null) {
579+
return getDefaultAttachedOutputs();
580+
}
581+
return attachedOutputs.getDirNames();
582+
}
583+
584+
private List<DirName> getDefaultAttachedOutputs() {
585+
List<DirName> defaults = new ArrayList<>();
586+
587+
DirName classes = new DirName();
588+
classes.setValue("classes");
589+
defaults.add(classes);
590+
591+
DirName testClasses = new DirName();
592+
testClasses.setValue("test-classes");
593+
defaults.add(testClasses);
594+
595+
return defaults;
579596
}
580597

581598
@Override

src/main/mdo/build-cache-config.mdo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,20 @@ under the License.
374374
-->
375375
<class>
376376
<name>AttachedOutputs</name>
377-
<description>Section relative to outputs which are not artifacts but need to be saved/restored.</description>
377+
<description>Section relative to outputs which are not artifacts but need to be saved/restored.
378+
If not specified, defaults to caching 'classes' and 'test-classes' directories.</description>
378379
<fields>
379380
<field>
380381
<name>dirNames</name>
381382
<association>
382383
<type>DirName</type>
383384
<multiplicity>*</multiplicity>
384385
</association>
385-
<description>Path to a directory containing files which needs to be saved/restored (relative to the build directory).</description>
386+
<description>Path to a directory containing files which needs to be saved/restored (relative to the build directory).
387+
Default: classes and test-classes directories are cached if this section is not specified.</description>
386388
</field>
387389
</fields>
388-
</class>
389-
<class>
390+
</class> <class>
390391
<name>DirName</name>
391392
<description><![CDATA[Path to a directory containing files which needs to be saved/restored (relative to the build directory).
392393
<br>

src/site/markdown/usage.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ When a configuration is disabled by default in the config, it can be enabled via
7272

7373
Build cache extension is generally compatible with IDEs with one limitation:
7474

75-
* The cache doesn't restore the entire project state. Compiled classes, unpacked artifacts, and similar ones typically
76-
will not be restored in the build directory (aka `target`). Configure your IDE to not use Maven
77-
build (`target`) directories for compilation and execution. In that case, IDE will provide fast compilation using
78-
native caches, and
79-
the build cache will supplement that with fast builds.
75+
* The cache restores `classes` and `test-classes` directories by default, but may not restore other artifacts like
76+
unpacked dependencies or generated resources. Configure your IDE to not use Maven build (`target`) directories for
77+
compilation and execution if you experience issues. In that case, IDE will provide fast compilation using
78+
native caches, and the build cache will supplement that with fast builds.

0 commit comments

Comments
 (0)