apache / apache/maven-build-cache-extension
Maven Build Cache Extension incorrectly handles --module-version compiler arguments for Java modules, causing cache invalidation on every build despite no source code changes
- Dominant language
- Java
- Stars
- 163
- Forks
- 77
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 4
Description
### Affected version
1.2.0
### Bug description
**Environment**
- Maven: 4.0.0-rc-4
- Java: 24
- Maven Compiler Plugin: 3.14.0
- Project Type: Multi-module project with module-info.java files
**Expected Behavior**
Subsequent `mvn verify runs` should use cached compilation results when no source code has changed.
**Actual Behavior**
Every `mvn verify` run forces full project rebuilds with these error messages:
> [INFO] Plugin parameter mismatch found. Parameter: compilerArgs, expected: [-Xlint:all,-module,-requires-automatic,-requires-transitive-automatic,-missing-explicit-ctor, -Xdiags:verbose, -Werror, --module-version, 1.0-SNAPSHOT], actual:
> [-Xlint:all,-module,-requires-automatic,-requires-transitive-automatic,-missing-explicit-ctor, -Xdiags:verbose, -Werror]
> [INFO] Mojo cached parameters mismatch with actual, forcing full project build. Mojo: compiler:compile
> [INFO] A cached mojo is not consistent, continuing with non cached build
>
**Root Cause Analysis**
The Maven Build Cache Extension has inconsistent behavior when tracking compiler arguments for Java modules:
1. During Cache Storage: Records `--module-version ${project.version}` as an expected parameter
2. During Cache Validation: The actual runtime parameters don't include `--module-version`
3. Result: Parameter mismatch causes cache invalidation
**Technical Details**
Maven Compiler Plugin Configuration
```
org.apache.maven.plugins
maven-compiler-plugin
3.14.0
true
512m
2048m
true
-Xlint:all,-module,-requires-automatic,-requires-transitive-automatic,-missing-explicit-ctor
-Xdiags:verbose
-Werror
```
**Module Structure**
Project contains module-info.java files in multiple modules:
- server/src/main/java/module-info.java
- tax/src/main/java/module-info.java
- simulator/src/main/java/module-info.java
**Attempted Workarounds**
All of the following configurations still exhibit the same issue:
1. Empty moduleVersion:
2. Null moduleVersion:
3. Explicit moduleVersion: ${project.version}
4. Explicit compilerArgs: Adding --module-version manually to compilerArgs (causes duplicate parameters)
**Reproduction Steps**
1. Create a multi-module Maven project with module-info.java files
2. Configure Maven Compiler Plugin with compilerArgs
3. Enable Maven Build Cache Extension
4. Run `mvn clean verify` (builds successfully, creates cache)
5. Run `mvn verify` again (should use cache but forces full rebuild instead)
**Impact**
- Build Performance: 3-5x slower builds due to cache misses
- Development Workflow: Affects incremental build efficiency
- CI/CD: Increased build times in continuous integration
**Expected Fix**
Maven Build Cache Extension should consistently track module versioning parameters between cache storage and validation phases, either:
1. Always include `--module-version` in both expected and actual parameters, or
2. Never include `--module-version` in either set when not explicitly configured
**Workaround**
Currently, no effective workaround exists. The issue persists regardless of moduleVersion configuration attempts.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the cache mismatch with a multi-module Maven project containing server/src/main/java/module-info.java, tax/src/main/java/module-info.java, and simulator/src/main/java/module-info.java. Run mvn clean verify followed by mvn verify and compare the compiler:compile parameters involving --module-version. Done means the second build reuses cached compilation results without reporting a parameter mismatch.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100