Skip to content

fix(ci): #1594 remove dual Maven cache stomping local SNAPSHOT artifacts - #2117

Merged
lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:fix/1594-remove-redundant-maven-cache
May 21, 2026
Merged

lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:fix/1594-remove-redundant-maven-cache

Conversation

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor

Summary

Closes #1594.

  • Drop cache: maven from every actions/setup-java invocation in build-verify.yml and build-container.yml. The explicit actions/cache@v5 block (keyed on github.run_id) becomes the single source of truth for ~/.m2/repository.
  • Remove the per-job mvn -B -DskipTests install workaround from package-webapp, integration-tests, fuzzing-tests, and javadoc-check. It was masking the symptom; with the dual cache gone, the cached SNAPSHOTs from build-install now restore cleanly.

Why

Two caches were active for ~/.m2/repository:

  1. actions/setup-java with cache: maven (keyed on **/pom.xml hashes)
  2. An explicit actions/cache@v5 block (keyed on github.run_id)

setup-java runs first and restores its pom-hash-keyed cache — likely a stale repo from an earlier unrelated run since pom hashes rarely change. The explicit actions/cache step then layers on top, but the resulting state can miss the SNAPSHOT artifacts build-install just installed. That's why downstream jobs needed the workaround.

GitHub's own setup-java caveat calls this anti-pattern out: when you manage ~/.m2/repository with an explicit actions/cache, don't also set cache: maven on setup-java.

Scope

  • build-verify.yml: 5× cache: maven removed, 4× workaround mvn install removed.
  • build-container.yml: 1× cache: maven removed. Its mvn -Pprod -DskipTests install step is the actual job (producing the prod jar with the Angular UI for the container image), not a workaround — left untouched.
  • package-native.yml: unchanged. It uses cache: maven without an explicit actions/cache block, so it isn't exhibiting the dual-cache conflict.

Test plan

  • Branch CI on fork — all 5 jobs (build-install, package-webapp, integration-tests, fuzzing-tests, javadoc-check) green without the workaround.
  • CI on this PR after open.

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@lbroudoux

Copy link
Copy Markdown
Member

CI is green on my fork : https://github.com/Git-HimanshuRathi/microcks/actions/runs/25726875878

Yes, but you didn't introduce new classes in - let's say - util module and then use them in webapp. Do you?

The thing is don't get here is the one you explained above:

The explicit actions/cache step then layers on top, but the resulting state can miss the SNAPSHOT artifacts build-install just installed.

Why? If snapshots have been installed, then they must be present in ~/.m2/repository and thus can be cached, restored, and made available for the downstream jobs...

@lbroudoux

lbroudoux commented May 12, 2026 •

Copy link
Copy Markdown
Member

From my understanding, it should be possible to manage 2 different caches:

  • 1 global, shared between GHA runs - until pom.xml change - that contains all the pulled dependencies
  • 1 local, shared between jobs within the same GHA run that contains the local~/.m2/repository folder initialized from a global cache restoration + the SNAPSHOTS layered on top...

That's what I was trying to achieve previously.

If we remove the cache from the JDK setup step, I'm afraid we'll have to fetch all the project dependencies on each and every run, and this will take longer than reinstalling with tests skipped. Don't you think?

Heyy-Himanshuu added a commit to Heyy-Himanshuu/microcks that referenced this pull request May 12, 2026
… scenario

Per maintainer feedback on microcks#2117: my earlier removal of cache: maven
was unproven (fork CI never added a new class) and sacrificed the
~400 MB Maven Central global cache.

Restore cache: maven on every actions/setup-java in build-verify.yml
and build-container.yml. Keep the per-job workaround removed. Add a
synthetic CacheRepoProbe class in commons/util referenced from
MicrocksApplication so downstream jobs can only compile if the new
build-install SNAPSHOT actually made it through the cache.

Expected outcomes on CI:
- Green: the workaround was redundant; dual-cache works as intended;
  drop the probe + open the cleaner PR.
- Red: dual-cache really does conflict; revert this commit's
  cache: maven and the previous PR shape (drop cache: maven) becomes
  the necessary fix.

This commit is temporary and will be amended out before merge.

Signed-off-by: Git-HimanshuRathi <[email protected]>
…-install

Root cause: in build-install, the actions/cache step was the LAST
step in the job — positioned AFTER `mvn -B clean install`. Because
actions/cache RESTORES at the position it is encountered (and only
SAVES at job end), the restore ran AFTER the build. The primary key
maven-repo-${run_id} did not yet exist for the current run, so
restore-keys fell back to a PRIOR run's maven-repo-* cache and
extracted stale SNAPSHOTs ON TOP of the freshly installed ones. The
job-end save then captured the stale state under the current run_id.
Downstream jobs (package-webapp, integration-tests, fuzzing-tests,
javadoc-check) restored that stale cache and could not find newly
added classes — exactly the symptom from May's log:
  "Cache restored from key: maven-repo-147564147"  ← prior run id

The per-job `mvn -B -DskipTests install` workaround landed in
cbf5d85/63e70f5/dce1290 was masking the bug by forcing a rebuild.

Fix: move the Cache Maven dependencies step BEFORE the
`mvn -B clean install` step in build-install (matching the order
every downstream job already used). The restore now uses any
prior cache as a starting point; mvn install then installs fresh
SNAPSHOTs which overwrite the stale ones; the job-end save captures
the fresh state under the current run_id. Drop the per-job
reinstall workaround from package-webapp, integration-tests,
fuzzing-tests, and javadoc-check.

cache: maven on actions/setup-java is intentionally kept — it
provides a separate global cache (keyed on pom.xml hashes) that
survives across CI runs and is independent of the per-run
actions/cache, so Maven Central downloads do not need to repeat
on every run. It is not the source of the dual-cache conflict.

Validated empirically on Git-HimanshuRathi/microcks by adding a
new class in commons/util referenced from webapp:
  - Without this fix: package-webapp / javadoc-check fail with
    "cannot find symbol" on the new class (bug reproduced).
  - With this fix: all 5 build-verify jobs green.

Signed-off-by: Git-HimanshuRathi <[email protected]>
@Heyy-Himanshuu
Heyy-Himanshuu force-pushed the fix/1594-remove-redundant-maven-cache branch from a3e2a1e to 8d04bbf Compare May 12, 2026 15:09
@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@lbroudoux You were right original diagnosis was wrong. Pushed an experimental probe class in commons/util referenced from webapp to actually reproduce the bug, then iterated:

  • Pass A (both caches + probe): red. Bug reproduced, but cache: maven is present same as before.
  • Pass B (drop cache: maven, keep probe): still red. Refutes the dual-cache theory.
  • Pass C (keep cache: maven, move actions/cache before mvn install in build-install): green.

Real root cause: in build-install, the actions/cache step was the last step. actions/cache restores at the position it's encountered, not at job start. With the step after mvn install, the primary key maven-repo-${run_id} didn't exist yet, so restore-keys fell back to a prior run's cache and extracted stale SNAPSHOTs on top of the freshly installed ones. Job-end save then captured the stale state exactly your log:

Cache restored from key: maven-repo-147564147   ← prior run, not the current one

The workaround was forcing a fresh mvn install to overwrite the stale cache in each downstream job.

Fix: move the cache step before the build in build-install (matching every downstream job's order). cache: maven stays global Maven Central cache preserved. Workaround removed from all 4 downstream jobs. Squashed to one clean commit (8d04bbfd), force-pushed. Probe deleted. Net diff is 10 lines in one file. Sorry for the noise.

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@lbroudoux anything wrong with this PR ?

@lbroudoux

Copy link
Copy Markdown
Member

@lbroudoux anything wrong with this PR ?

Nothing wrong, but not time to review this in details for this week. Thanks for your patience!

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am wondering if we couldn't also remove the install done in build-containers? Can you check this?

Comment thread .github/workflows/build-verify.yml Resolved
@lbroudoux lbroudoux added kind/bug component/build github_actions Pull requests that update GitHub Actions code labels May 18, 2026
@lbroudoux lbroudoux added this to the 1.15.0 milestone May 21, 2026
@lbroudoux
lbroudoux merged commit 4105e79 into microcks:master May 21, 2026
5 checks passed
@Heyy-Himanshuu
Heyy-Himanshuu deleted the fix/1594-remove-redundant-maven-cache branch May 21, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/build github_actions Pull requests that update GitHub Actions code kind/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: package-webapp and integration-tests compilation are failing when adding new classes

2 participants