-
Notifications
You must be signed in to change notification settings - Fork 59
Fix #375: Capture plugin properties at validation time to eliminate timing mismatch #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
57a76d8 to
d2c8071
Compare
elharo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to run mvn spotless:apply
- Upgrade spotless-maven-plugin from 2.44.5 to 3.0.0 - Upgrade palantir-java-format from 2.56.0 to 2.81.0 for Java 25 support - Run mvn spotless:apply to format code Addresses review feedback on PR apache#395.
|
@elharo Done. Try now. |
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
- Split run-on sentence in AssertionError message - Use HashMap import instead of fully qualified name - Move Mojo variable declaration into try block (nested try-finally) - Return defensive copy from getValidationTimeEvents() for encapsulation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Split run-on sentence in AssertionError message - Use HashMap import instead of fully qualified name - Move Mojo variable declaration into try block (nested try-finally) - Return defensive copy from getValidationTimeEvents() for encapsulation
43445c6 to
fda621a
Compare
- Split run-on sentence in AssertionError message - Use HashMap import instead of fully qualified name - Move Mojo variable declaration into try block (nested try-finally) - Make getValidationTimeEvents() package-private
fda621a to
6cf3a36
Compare
…nate timing mismatch Maven 4 automatically injects --module-version into compiler arguments during execution, but cache validation happens before execution. This creates a timing mismatch that causes cache invalidation. This fix captures properties at validation time for ALL builds and stores ONLY validation-time values in the cache, ensuring consistent reading at the same lifecycle point. Changes: - Modified CacheResult to store validation-time mojo events - Added captureValidationTimeProperties() to BuildCacheMojosExecutionStrategy - Modified execute() to capture properties after findCachedBuild() - Modified save() to store ONLY validation-time events (AssertionError if missing) - Added comprehensive integration tests (Maven4Jpms, ExplicitModuleVersion, NonJpms, MultiModule) Benefits: - No configuration required (vs ignorePattern in PR apache#391) - Fixes root cause (timing mismatch) not symptom (value mismatch) - Works for ALL Maven 4 auto-injected properties - Preserves execution-time logging for debugging Alternative to PR apache#391
- Upgrade spotless-maven-plugin from 2.44.5 to 3.0.0 - Upgrade palantir-java-format from 2.56.0 to 2.81.0 for Java 25 support - Run mvn spotless:apply to format code Addresses review feedback on PR apache#395.
- Split run-on sentence in AssertionError message - Use HashMap import instead of fully qualified name - Move Mojo variable declaration into try block (nested try-finally) - Make getValidationTimeEvents() package-private
6cf3a36 to
04b6246
Compare
- Fix invalid XML in pom.xml comment (-- not allowed in XML comments) - Fix cache config XML validation errors by simplifying config - Change tests to use 'package' goal instead of 'compile' since cache extension stores artifacts, not intermediate output directories - Fix AssertionError when running clean-only builds by gracefully skipping cache storage when no cacheable mojos executed
|
@elharo I've pushed a commit that should fix the latest build failures. Try now. |
Put LOGGER.debug() call on single line to satisfy Spotless formatting rules.
c4c7a6c to
86c7750
Compare
|
It looks like the latest build errors are not related to this PR. Can it be merged? Do you need to do something else to fix the build? |
|
Absolutely nothing should be merged on a failing build. A failing build blocks everything. |
...jects/maven4-jpms-module/src/main/java/org/apache/maven/caching/test/maven4/HelloMaven4.java
Show resolved
Hide resolved
...dule-version/src/main/java/org/apache/maven/caching/test/explicit/ExplicitVersionModule.java
Show resolved
Hide resolved
src/test/projects/explicit-module-version/src/main/java/module-info.java
Show resolved
Hide resolved
...-module-jpms/module-a/src/main/java/org/apache/maven/caching/test/multi/modulea/ModuleA.java
Show resolved
Hide resolved
src/test/projects/multi-module-jpms/module-a/src/main/java/module-info.java
Show resolved
Hide resolved
...-module-jpms/module-b/src/main/java/org/apache/maven/caching/test/multi/moduleb/ModuleB.java
Show resolved
Hide resolved
...s/non-jpms-project/src/main/java/org/apache/maven/caching/test/nonjpms/RegularJavaClass.java
Show resolved
Hide resolved
|
@elharo Agreed, but is anyone taking a look at the failing build? |
Add missing Apache Software Foundation license headers to all test project files as required by Apache conventions: - explicit-module-version: pom.xml, extensions.xml, module-info.java, ExplicitVersionModule.java - maven4-jpms-module: pom.xml, extensions.xml, module-info.java, HelloMaven4.java - multi-module-jpms: parent and module pom.xml files, extensions.xml, module-info.java, ModuleA.java, ModuleB.java - non-jpms-project: pom.xml, extensions.xml, RegularJavaClass.java maven-build-cache-config.xml files already had correct license headers.
Problem
Maven 4 automatically injects
--module-version ${project.version}into compiler arguments during execution, but the build cache validates properties before execution. This creates a timing mismatch that causes cache invalidation:Root Cause Analysis
The cache extension currently reads plugin properties at different lifecycle points for different builds:
The problem: validation reads BEFORE injection, storage reads AFTER injection.
Solution
Capture properties at validation time for ALL builds (even when no cache exists). Store ONLY validation-time values in the cache. This ensures both validation and storage read at the same lifecycle point.
Implementation
CacheResultto store validation-time mojo eventsBuildCacheMojosExecutionStrategyto capture properties immediately afterfindCachedBuild()save()to store ONLY validation-time events (fails withAssertionErrorif missing)Key Code Changes
Note: Execution-time values are still captured by
MojoParametersListenerfor logging/debugging during the build, but are NOT stored in the cache.New Timeline (Both Builds)
What Gets Stored vs. Logged
This approach ensures cache consistency while preserving debugging information in build logs.
Benefits Over PR #391
ignorePattern)Testing
Created comprehensive integration tests:
--module-versionmoduleVersionconfigurationAll tests verify:
ignorePatternconfiguration requiredBackward Compatibility
ignorePatternstill works but is no longer necessary for Maven 4 injectionAlternative Approaches Considered
Related Issues
Migration
No migration needed. This change is transparent to users. Existing projects will benefit automatically.