Skip to content

Maven Build Cache Extension incorrectly handles --module-version compiler arguments for Java modules, causing cache invalidation on every build despite no source code changes #375

@cowwoc

Description

@cowwoc

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

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.14.0</version> <configuration> <fork>true</fork> <meminitial>512m</meminitial> <maxmem>2048m</maxmem> <useIncrementalCompilation>true</useIncrementalCompilation> <compilerArgs> <arg>-Xlint:all,-module,-requires-automatic,-requires-transitive-automatic,-missing-explicit-ctor</arg> <arg>-Xdiags:verbose</arg> <arg>-Werror</arg> </compilerArgs> </configuration> </plugin> 

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions