Skip to content
65 changes: 56 additions & 9 deletions src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,15 @@ public boolean isLogAllProperties(MojoExecution mojoExecution) {
}

private GoalReconciliation findReconciliationConfig(MojoExecution mojoExecution) {
if (cacheConfig.getExecutionControl() == null) {
return null;
}
List<GoalReconciliation> reconciliation;

final ExecutionControl executionControl = cacheConfig.getExecutionControl();
if (executionControl.getReconcile() == null) {
return null;
if (cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getReconcile() == null) {
// Use default reconciliation configs for common plugins
reconciliation = getDefaultReconciliationConfigs();
} else {
reconciliation = cacheConfig.getExecutionControl().getReconcile().getPlugins();
}

final List<GoalReconciliation> reconciliation =
executionControl.getReconcile().getPlugins();

for (GoalReconciliation goalReconciliationConfig : reconciliation) {
final String goal = mojoExecution.getGoal();

Expand All @@ -271,6 +268,56 @@ private GoalReconciliation findReconciliationConfig(MojoExecution mojoExecution)
return null;
}

private List<GoalReconciliation> getDefaultReconciliationConfigs() {
List<GoalReconciliation> defaults = new ArrayList<>();

// maven-compiler-plugin:compile - track source, target, release
GoalReconciliation compilerCompile = new GoalReconciliation();
compilerCompile.setArtifactId("maven-compiler-plugin");
compilerCompile.setGoal("compile");

TrackedProperty source = new TrackedProperty();
source.setPropertyName("source");
compilerCompile.addReconcile(source);

TrackedProperty target = new TrackedProperty();
target.setPropertyName("target");
compilerCompile.addReconcile(target);

TrackedProperty release = new TrackedProperty();
release.setPropertyName("release");
compilerCompile.addReconcile(release);

defaults.add(compilerCompile);

// maven-compiler-plugin:testCompile - track source, target, release
GoalReconciliation compilerTestCompile = new GoalReconciliation();
compilerTestCompile.setArtifactId("maven-compiler-plugin");
compilerTestCompile.setGoal("testCompile");

TrackedProperty testSource = new TrackedProperty();
testSource.setPropertyName("source");
compilerTestCompile.addReconcile(testSource);

TrackedProperty testTarget = new TrackedProperty();
testTarget.setPropertyName("target");
compilerTestCompile.addReconcile(testTarget);

TrackedProperty testRelease = new TrackedProperty();
testRelease.setPropertyName("release");
compilerTestCompile.addReconcile(testRelease);

defaults.add(compilerTestCompile);

// maven-install-plugin:install - always run (empty reconciliation means it's tracked)
GoalReconciliation install = new GoalReconciliation();
install.setArtifactId("maven-install-plugin");
install.setGoal("install");
defaults.add(install);

return defaults;
}

@Nonnull
@Override
public List<PropertyName> getLoggedProperties(MojoExecution mojoExecution) {
Expand Down
11 changes: 11 additions & 0 deletions src/site/markdown/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ Add `executionControl/runAlways` section:
</executionControl>
```

### Default Reconciliation Behavior

The build cache extension automatically tracks certain critical plugin properties by default, even without explicit
`executionControl` configuration:

* **maven-compiler-plugin** (`compile` and `testCompile` goals): Tracks `source`, `target`, and `release` properties
* **maven-install-plugin** (`install` goal): Tracked to ensure artifacts are installed when needed

This default behavior prevents common cache invalidation issues, particularly in multi-module JPMS (Java Platform Module System)
projects where compiler version changes can cause compilation failures.

### I occasionally cached build with `-DskipTests=true`, and tests do not run now

If you add command line flags to your build, they do not participate in effective pom - Maven defers the final value
Expand Down