Skip to content

fix(maven): include test sources in testCompile task hash#34422

Open
MaxKless wants to merge 1 commit intomasterfrom
fix/maven-testcompile-hash
Open

fix(maven): include test sources in testCompile task hash#34422
MaxKless wants to merge 1 commit intomasterfrom
fix/maven-testcompile-hash

Conversation

@MaxKless
Copy link
Collaborator

Current Behavior

The maven-compiler-plugin:testCompile Nx target hash never includes test source files (src/test/java/**/*.java). Modifying test sources does not invalidate the testCompile cache, so stale compiled test classes can be served from cache.

This is caused by two compounding bugs:

  1. CacheConfig uses parameter name testCompileSourceRoots, but the Maven compiler plugin descriptor names the field compileSourceRoots for both compile and testCompile mojos (they differ only in default-value). MojoAnalyzer looks it up in the mojo descriptor, gets null, and silently skips it via ?: return@forEach.

  2. MavenExpressionResolver has a special-case block that resolves source roots by parameter name rather than by the parameter's default-value expression. Since both mojos share the field name compileSourceRoots, testCompile always resolves to project.compileSourceRoots (main sources) instead of project.testCompileSourceRoots (test sources).

Expected Behavior

Changes to test source files correctly invalidate the testCompile cache entry, causing Maven to recompile test classes on the next run.

Changes

  • CacheConfig.kt: Fix parameter name from testCompileSourceRoots to compileSourceRoots (the actual name in the Maven mojo descriptor)
  • MavenExpressionResolver.kt: Remove the special-case block that short-circuited resolution by parameter name. The existing resolveCollectionParameterresolveCollectionExpression path already correctly resolves based on the default-value expression (${project.testCompileSourceRoots} for testCompile vs ${project.compileSourceRoots} for compile)
  • E2e test: Added maven-test-compile-cache.test.ts that validates test source changes invalidate the testCompile cache without any nx reset workaround

Related Issue(s)

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]>
@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f492fbf
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/698dc3d739f7ec00081d4c33
😎 Deploy Preview https://deploy-preview-34422--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 12, 2026

View your CI Pipeline Execution ↗ for commit f492fbf

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ❌ Failed 11m 55s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 47s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-12 12:29:38 UTC

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f492fbf
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/698dc3d70b5fca0008a62704
😎 Deploy Preview https://deploy-preview-34422--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant