fix(maven): include test sources in testCompile task hash#34422
Open
fix(maven): include test sources in testCompile task hash#34422
Conversation
The `maven-compiler-plugin:testCompile` Nx target hash never included test source files due to two compounding bugs: 1. CacheConfig used parameter name `testCompileSourceRoots`, but the Maven compiler plugin descriptor names the field `compileSourceRoots` for both compile and testCompile mojos. MojoAnalyzer looked it up, got null, and silently skipped it. 2. MavenExpressionResolver had a special-case that resolved by parameter name instead of the default-value expression. Since both mojos share the name `compileSourceRoots`, testCompile always got main sources. Fix: use correct parameter name in CacheConfig and remove the broken special-case, letting the existing resolveCollectionParameter path handle it via the default-value expression. Co-Authored-By: Claude Opus 4.6 <[email protected]>
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit f492fbf
☁️ Nx Cloud last updated this comment at |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
The
maven-compiler-plugin:testCompileNx target hash never includes test source files (src/test/java/**/*.java). Modifying test sources does not invalidate thetestCompilecache, so stale compiled test classes can be served from cache.This is caused by two compounding bugs:
CacheConfig uses parameter name
testCompileSourceRoots, but the Maven compiler plugin descriptor names the fieldcompileSourceRootsfor bothcompileandtestCompilemojos (they differ only indefault-value).MojoAnalyzerlooks it up in the mojo descriptor, getsnull, and silently skips it via?: return@forEach.MavenExpressionResolver has a special-case block that resolves source roots by parameter name rather than by the parameter's
default-valueexpression. Since both mojos share the field namecompileSourceRoots,testCompilealways resolves toproject.compileSourceRoots(main sources) instead ofproject.testCompileSourceRoots(test sources).Expected Behavior
Changes to test source files correctly invalidate the
testCompilecache entry, causing Maven to recompile test classes on the next run.Changes
testCompileSourceRootstocompileSourceRoots(the actual name in the Maven mojo descriptor)resolveCollectionParameter→resolveCollectionExpressionpath already correctly resolves based on thedefault-valueexpression (${project.testCompileSourceRoots}for testCompile vs${project.compileSourceRoots}for compile)maven-test-compile-cache.test.tsthat validates test source changes invalidate the testCompile cache without anynx resetworkaroundRelated Issue(s)