Skip to content

SONARJAVA-7320 Cache safe Maven module results in PR checks - #6500

Draft
romainbrenguier wants to merge 7 commits into
masterfrom
romain/maven-caching
Draft

romainbrenguier wants to merge 7 commits into
masterfrom
romain/maven-caching

Conversation

@romainbrenguier

@romainbrenguier romainbrenguier commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Part of AP-1237

Summary

  • Pin Apache Maven Build Cache Extension 1.3.0 and cache module results for Windows clean verify, sanity test-source clean compile, and custom-rules example clean package.
  • Restore job-specific GitHub Actions cache archives on PRs. Save only after successful master pushes or same-repository PR jobs; fork PRs have no save step.
  • Keep live-service tests, ruling/plugin QA, license aggregation, publication, and deployment outside Apache cache reuse.
  • Keep cacheable CI commands on the stable checkout POM version. The sanity job sets the deployed version after its cached compile and before the live test.

Validation

  • Full reactor: uncached and cold verification ran 381 goals; clean warm verification restored 20 modules and ran 124 goals. Source, shared sample, Java test, XML fixture, skip-poisoning, compiler-setting, and rollback checks passed.
  • Sanity preparation: uncached/cold clean compile ran 62 goals; clean warm run restored eight modules and ran eight goals. Source invalidation and a second clean checkout with copied cache passed.
  • Custom rules: uncached/cold clean package ran 11 goals; clean warm run restored the module and 13 Surefire reports, running one goal. Source, failing test, fixture, compiler-setting, partial-test, and rollback checks passed. Each skipped-test and ignored-failure poisoning pair exited 0 then 1 after the POM fix. A second clean checkout with copied cache passed.
  • Cross-PR CI reuse: the second stable-version Windows run restored 20 module results from its prior archive and passed full clean verify. Sanity restored all eight compile modules, then ran both live tests successfully. Custom rules restored its module while license aggregation still ran.
  • The deployed-version versions:set command succeeded in a disposable checkout and updated the root, sanity-source, and plugin POMs. Workflow YAML and diff checks passed; deep Vortex analysis found no issues in the latest changed files.

Remaining limits

Native remote transport is unconfigured. GitHub Actions archive reuse is verified for trusted PR updates; fork PRs cannot write shared archives. Service-backed and publication jobs remain uncached. Cache hits restore configured outputs, not the entire target directory.


Summary by Gitar

  • Build configuration:
    • Added maven-build-cache-extension 1.3.0 with .mvn/maven-build-cache-config.xml fingerprinting sources and POMs
    • Explicit skip, skipTests, and testFailureIgnore properties fingerprint test settings in root and custom-rules POMs
  • Reproducible artifacts:
    • The apache-build-cache profile pins Implementation-Build and Build-Time manifest entries
  • Developer guidance:
    • Documented cache opt-in in AGENTS.md and README.md, linking to docs/maven-build-cache.md

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Cache safe Maven module results in PR checks SONARJAVA-7320 Cache safe Maven module results in PR checks Nov 10, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7320

Comment thread java-frontend/pom.xml
Comment on lines +18 to +23
<maven.build.cache.input.1>../java-checks-test-sources/aws/src</maven.build.cache.input.1>
<maven.build.cache.input.2>../java-checks-test-sources/default/src</maven.build.cache.input.2>
<maven.build.cache.input.3>../java-checks-test-sources/java-17/src</maven.build.cache.input.3>
<maven.build.cache.input.4>../java-checks-test-sources/spring-3.2/src</maven.build.cache.input.4>
<maven.build.cache.input.5>../java-checks-test-sources/spring-web-4.0/src</maven.build.cache.input.5>
<maven.build.cache.input.6>../java-checks-test-sources/quarkus-arc-3.15/src</maven.build.cache.input.6>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Test-source POM/classpath changes don't invalidate consumer module caches

The frontend, checks, AWS checks, and testkit modules add only ../java-checks-test-sources/*/src as extra cache inputs. Their tests also read outputs built from the test-source POMs. DependencyVersionInferenceTest loads ../java-checks-test-sources/default/target/test-classpath.txt and spring-3.2/target/test-classpath.txt, and JParserTestUtils resolves semantics from each test project's target/test-classpath.txt. Those files come from maven-dependency-plugin:build-classpath in java-checks-test-sources/pom.xml, driven by each sub-POM's dependencies. None of these modules has a Maven dependency on the test-source modules, so a change to a sub-POM (for example a Renovate bump of a Spring/AWS version in java-checks-test-sources/default/pom.xml) leaves their fingerprints unchanged.

The CI restore falls back to the config_prefix key, so an older archive can still be restored after the POM hash changes. The extension then reports hits for java-frontend/java-checks and restores old Surefire reports without running the tests that depend on the new classpath. That breaks the PR's claim that an outdated entry can never stand in for tests that must run.

Fix: add the test-source POMs (or the generated test-classpath.txt files) as extra inputs for each consumer module. Alternatively, declare the test-source modules as test-scoped reactor dependencies so their fingerprints propagate.

Also fingerprint the test-source POMs that determine test-classpath.txt (repeat for java-checks, java-checks-aws, and java-checks-testkit with the matching sub-modules):

<maven.build.cache.input.7>../java-checks-test-sources/pom.xml</maven.build.cache.input.7>
<maven.build.cache.input.8>../java-checks-test-sources/default/pom.xml</maven.build.cache.input.8>
<maven.build.cache.input.9>../java-checks-test-sources/aws/pom.xml</maven.build.cache.input.9>
<maven.build.cache.input.10>../java-checks-test-sources/java-17/pom.xml</maven.build.cache.input.10>
<maven.build.cache.input.11>../java-checks-test-sources/spring-3.2/pom.xml</maven.build.cache.input.11>
<maven.build.cache.input.12>../java-checks-test-sources/spring-web-4.0/pom.xml</maven.build.cache.input.12>
<maven.build.cache.input.13>../java-checks-test-sources/quarkus-arc-3.15/pom.xml</maven.build.cache.input.13>
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@datadog-sonarsource

datadog-sonarsource Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 308342f | Docs | Give us feedback!

@gitar-bot

gitar-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 closed / 1 findings

🟡 Medium risk · Adding Apache Maven module-result reuse to CI could restore stale outputs if fingerprints omit an input, potentially masking build or test failures.

Adds Apache Maven build cache for PR checks on the Windows verification job, sanity test-source compilation, and custom-rules packaging, with restore on PRs and save on master or same-repo PR jobs. Changes requested: the cache key for java-frontend, java-checks, java-checks-aws, and java-checks-testkit does not include the test-source POMs or generated test-classpath.txt files they read, so a dependency bump in java-checks-test-sources can leave stale Surefire results restored via the config_prefix fallback. Add those test-source POMs or classpath files as extra cache inputs for each consumer module, or declare the test-source modules as test-scoped reactor dependencies.

⚠️ Bug: Test-source POM/classpath changes don't invalidate consumer module caches

📄 java-frontend/pom.xml:18-23 📄 java-checks/pom.xml:16-23 📄 java-checks-aws/pom.xml:16-19 📄 java-checks-testkit/pom.xml:16-18 📄 .github/actions/apache-maven-build-cache/action.yml:35-37

The frontend, checks, AWS checks, and testkit modules add only ../java-checks-test-sources/*/src as extra cache inputs. Their tests also read outputs built from the test-source POMs. DependencyVersionInferenceTest loads ../java-checks-test-sources/default/target/test-classpath.txt and spring-3.2/target/test-classpath.txt, and JParserTestUtils resolves semantics from each test project's target/test-classpath.txt. Those files come from maven-dependency-plugin:build-classpath in java-checks-test-sources/pom.xml, driven by each sub-POM's dependencies. None of these modules has a Maven dependency on the test-source modules, so a change to a sub-POM (for example a Renovate bump of a Spring/AWS version in java-checks-test-sources/default/pom.xml) leaves their fingerprints unchanged.

The CI restore falls back to the config_prefix key, so an older archive can still be restored after the POM hash changes. The extension then reports hits for java-frontend/java-checks and restores old Surefire reports without running the tests that depend on the new classpath. That breaks the PR's claim that an outdated entry can never stand in for tests that must run.

Fix: add the test-source POMs (or the generated test-classpath.txt files) as extra inputs for each consumer module. Alternatively, declare the test-source modules as test-scoped reactor dependencies so their fingerprints propagate.

Also fingerprint the test-source POMs that determine test-classpath.txt (repeat for java-checks, java-checks-aws, and java-checks-testkit with the matching sub-modules)
<maven.build.cache.input.7>../java-checks-test-sources/pom.xml</maven.build.cache.input.7>
<maven.build.cache.input.8>../java-checks-test-sources/default/pom.xml</maven.build.cache.input.8>
<maven.build.cache.input.9>../java-checks-test-sources/aws/pom.xml</maven.build.cache.input.9>
<maven.build.cache.input.10>../java-checks-test-sources/java-17/pom.xml</maven.build.cache.input.10>
<maven.build.cache.input.11>../java-checks-test-sources/spring-3.2/pom.xml</maven.build.cache.input.11>
<maven.build.cache.input.12>../java-checks-test-sources/spring-web-4.0/pom.xml</maven.build.cache.input.12>
<maven.build.cache.input.13>../java-checks-test-sources/quarkus-arc-3.15/pom.xml</maven.build.cache.input.13>
🤖 Prompt for agents
Code Review: Adds Apache Maven build cache for PR checks on the Windows verification job, sanity test-source compilation, and custom-rules packaging, with restore on PRs and save on master or same-repo PR jobs. Changes requested: the cache key for java-frontend, java-checks, java-checks-aws, and java-checks-testkit does not include the test-source POMs or generated `test-classpath.txt` files they read, so a dependency bump in `java-checks-test-sources` can leave stale Surefire results restored via the `config_prefix` fallback. Add those test-source POMs or classpath files as extra cache inputs for each consumer module, or declare the test-source modules as test-scoped reactor dependencies.

1. ⚠️ Bug: Test-source POM/classpath changes don't invalidate consumer module caches
   Files: java-frontend/pom.xml:18-23, java-checks/pom.xml:16-23, java-checks-aws/pom.xml:16-19, java-checks-testkit/pom.xml:16-18, .github/actions/apache-maven-build-cache/action.yml:35-37

   The frontend, checks, AWS checks, and testkit modules add only `../java-checks-test-sources/*/src` as extra cache inputs. Their tests also read outputs built from the test-source POMs. `DependencyVersionInferenceTest` loads `../java-checks-test-sources/default/target/test-classpath.txt` and `spring-3.2/target/test-classpath.txt`, and `JParserTestUtils` resolves semantics from each test project's `target/test-classpath.txt`. Those files come from `maven-dependency-plugin:build-classpath` in `java-checks-test-sources/pom.xml`, driven by each sub-POM's dependencies. None of these modules has a Maven dependency on the test-source modules, so a change to a sub-POM (for example a Renovate bump of a Spring/AWS version in `java-checks-test-sources/default/pom.xml`) leaves their fingerprints unchanged.
   
   The CI restore falls back to the `config_prefix` key, so an older archive can still be restored after the POM hash changes. The extension then reports hits for java-frontend/java-checks and restores old Surefire reports without running the tests that depend on the new classpath. That breaks the PR's claim that an outdated entry can never stand in for tests that must run.
   
   Fix: add the test-source POMs (or the generated `test-classpath.txt` files) as extra inputs for each consumer module. Alternatively, declare the test-source modules as test-scoped reactor dependencies so their fingerprints propagate.

   Fix (Also fingerprint the test-source POMs that determine test-classpath.txt (repeat for java-checks, java-checks-aws, and java-checks-testkit with the matching sub-modules)):
   <maven.build.cache.input.7>../java-checks-test-sources/pom.xml</maven.build.cache.input.7>
   <maven.build.cache.input.8>../java-checks-test-sources/default/pom.xml</maven.build.cache.input.8>
   <maven.build.cache.input.9>../java-checks-test-sources/aws/pom.xml</maven.build.cache.input.9>
   <maven.build.cache.input.10>../java-checks-test-sources/java-17/pom.xml</maven.build.cache.input.10>
   <maven.build.cache.input.11>../java-checks-test-sources/spring-3.2/pom.xml</maven.build.cache.input.11>
   <maven.build.cache.input.12>../java-checks-test-sources/spring-web-4.0/pom.xml</maven.build.cache.input.12>
   <maven.build.cache.input.13>../java-checks-test-sources/quarkus-arc-3.15/pom.xml</maven.build.cache.input.13>

Verification Rules 2/2 met PRs 2 inspected

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact PRs 2 inspected
Cross-PR 2 PRs inspected 0 open impacts

PR 6497: SONARJAVA-7236 Experiment: supply only the JDK classpath to semsitter Inspected
PR 6499: SONARJAVA-6048 Recognize qualified Deprecated annotations Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.
Unblock → Override a blocking verdict and allow merging.

Comment with these commands to change the behavior for this request:

Auto-apply Compact Unblock
gitar auto-apply:on         
gitar display:verbose         
gitar unblock         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
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