Skip to content

chore: improve Maven cache fallback strategy in GitHub Actions#1304

Merged
gnodet merged 1 commit intojline:masterfrom
gnodet:chore-improve-maven-cache-fallback
May 27, 2025
Merged

chore: improve Maven cache fallback strategy in GitHub Actions#1304
gnodet merged 1 commit intojline:masterfrom
gnodet:chore-improve-maven-cache-fallback

Conversation

@gnodet
Copy link
Copy Markdown
Member

@gnodet gnodet commented May 27, 2025

Problem

The current GitHub Actions workflow uses setup-java@v4 with cache: maven, which only performs exact cache key matching. When pom.xml files 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@v4 to gain more control over cache fallback behavior:

  • Primary key: ${{ runner.os }}-maven-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}
  • Restore keys (fallback order):
    1. ${{ runner.os }}-maven-${{ matrix.java }}- - Any cache for same OS and Java version
    2. ${{ runner.os }}-maven- - Any Maven cache for same OS

Benefits

  • Exact match: When pom.xml unchanged, uses exact cache
  • Smart fallback: When pom.xml changed, reuses previous cache and only downloads new/changed dependencies
  • Cross-version fallback: Can reuse caches across Java versions if needed
  • Faster CI: Significantly reduces build times by avoiding full dependency re-downloads

Testing

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

- 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
@gnodet gnodet added this to the 3.30.4 milestone May 27, 2025
@gnodet gnodet added the chore label May 27, 2025
@gnodet gnodet merged commit 0cfb48c into jline:master May 27, 2025
9 checks passed
@gnodet gnodet deleted the chore-improve-maven-cache-fallback branch May 27, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant