chore: improve Maven cache fallback strategy in GitHub Actions by gnodet · Pull Request #1304 · jline/jline3 (original) (raw)
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):
${{ runner.os }}-maven-${{ matrix.java }}-- Any cache for same OS and Java version${{ runner.os }}-maven-- Any Maven cache for same OS
Benefits
- ✅ Exact match: When
pom.xmlunchanged, uses exact cache - ✅ Smart fallback: When
pom.xmlchanged, 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