apache / apache/maven-build-cache-extension
Maven Build Cache not used when executing an additional plugin goal
- Dominant language
- Java
- Stars
- 163
- Forks
- 77
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 4
Description
### Affected version
1.2.0
### Bug description
The Maven Build Cache Extension works when lifecycle phases are executed, but does not seem te be active when an additional plugin goal is executed (e.g. `mvn verify dependency:tree`).
**Expected behavior**
When running `mvn verify dependency:tree` on a project that previously stored its build result in the Maven build cache, I expect the cached result to be restored.
**Actual behavior**
The previously cached result doesn't seem to be restored.
**Reproduction**
Here are the steps to reproduce this issue:
1. Create a simple Maven project called `my-app`.
```
❯ mvn archetype:generate \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.5 \
-DgroupId=com.example \
-DartifactId=my-app \
-Dversion=1.0.0-SNAPSHOT \
-DjavaCompilerVersion=21 \
-DinteractiveMode=false && cd my-app
```
2. Add the Maven Build Cache Extension.
```
❯ cat < .mvn/extensions.xml
org.apache.maven.extensions
maven-build-cache-extension
1.2.0
EOF
```
3. Build it for the first time, see the Maven Build Cache Extension storing the result in the local cache.
```
❯ mvn verify
(...)
[INFO] Local build was not found by checksum 0b97f1d6be2b14ce for com.example:my-app
(...)
[INFO] Saved Build to local file: /Users/nbreunese/.m2/build-cache/v1.1/com.example/my-app/0b97f1d6be2b14ce/local/buildinfo.xml
(...)
```
4. Clean and build again, and see the cached artifacts getting restored:
```
❯ mvn clean verify
(...)
[INFO] Found cached build, restoring com.example:my-app from cache by checksum 0b97f1d6be2b14ce
(...)
```
Up to here everything works as expected.
But now, when you run `verify` again, but add `dependency:tree` as an additional plugin goal, the build cache doesn't seem to be used, because there are no messages about restoring anything, and the tests are ran again:
```
❯ mvn clean verify dependency:tree
[INFO] Cache configuration is not available at configured path /Users/nbreunese/Projects/tmp/my-app/.mvn/maven-build-cache-config.xml, cache is enabled with defaults
[INFO] Using XX hash algorithm for cache
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.example:my-app >-------------------------
[INFO] Building my-app 1.0.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ my-app ---
[INFO] skip non existing resourceDirectory /Users/nbreunese/Projects/tmp/my-app/src/main/resources
[INFO]
[INFO] --- compiler:3.13.0:compile (default-compile) @ my-app ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ my-app ---
[INFO] skip non existing resourceDirectory /Users/nbreunese/Projects/tmp/my-app/src/test/resources
[INFO]
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ my-app ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- surefire:3.3.0:test (default-test) @ my-app ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.014 s -- in com.example.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.4.2:jar (default-jar) @ my-app ---
[INFO]
[INFO] --- dependency:3.7.0:tree (default-cli) @ my-app ---
[INFO] com.example:my-app:jar:1.0.0-SNAPSHOT
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.11.0:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | +- org.junit.platform:junit-platform-commons:jar:1.11.0:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] \- org.junit.jupiter:junit-jupiter-params:jar:5.11.0:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.086 s
[INFO] Finished at: 2025-10-27T14:25:17+01:00
[INFO] ------------------------------------------------------------------------
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the cache behavior with .mvn/extensions.xml and the commands mvn clean verify and mvn clean verify dependency:tree in the sample project described by the issue. Trace how the extension handles the lifecycle goals and the additional dependency:tree goal. Done means the cached result is restored and tests are not rerun when both commands are used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100