chore: improve Maven cache fallback strategy in GitHub Actions#1304
Merged
gnodet merged 1 commit intojline:masterfrom May 27, 2025
Merged
chore: improve Maven cache fallback strategy in GitHub Actions#1304gnodet merged 1 commit intojline:masterfrom
gnodet merged 1 commit intojline:masterfrom
Conversation
- Replace setup-java built-in cache with actions/cache@v4 for better control - Add restore-keys to fallback to previous commits' caches when pom.xml unchanged - Prevents re-downloading all Maven dependencies on every pom.xml change - Fallback order: exact match -> same Java version -> any Maven cache
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.
Problem
The current GitHub Actions workflow uses
setup-java@v4withcache: maven, which only performs exact cache key matching. Whenpom.xmlfiles change (even slightly), the cache key changes and all Maven dependencies must be re-downloaded, leading to slower CI builds.Solution
Replace the built-in caching with
actions/cache@v4to gain more control over cache fallback behavior:${{ runner.os }}-maven-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}${{ runner.os }}-maven-${{ matrix.java }}-- Any cache for same OS and Java version${{ runner.os }}-maven-- Any Maven cache for same OSBenefits
pom.xmlunchanged, uses exact cachepom.xmlchanged, reuses previous cache and only downloads new/changed dependenciesTesting
This change maintains the same cache paths (
~/.m2/repository) and is backward compatible with existing caches.Pull Request opened by Augment Code with guidance from the PR author