Gradle Build Cache Errors - "Corrupted" / Cache Miss in CI
A Gradle build-cache entry is corrupt or stale, so a task either fails to unpack a cached output or produces wrong results. A partially-written cache (often from an interrupted CI run) is the usual culprit.
What this error means
Builds fail intermittently with a cache-unpack error, or a task is incorrectly marked FROM-CACHE and produces stale outputs. Deleting the cache makes it pass, which points squarely at the cache.
> Task :app:compileJava FROM-CACHE
> Could not load entry ... from the build cache:
Cache entry 'a1b2c3...' is corrupt. Could not unpack.Common causes
Partially written cache entry
An interrupted or OOM-killed build can leave a half-written entry in the local or remote build cache. Reading it later fails to unpack.
Non-reproducible task inputs
A task whose inputs are not fully declared can be served a stale cached output that no longer matches reality, producing wrong-looking results.
How to fix it
Clear the cache and rebuild clean
Remove the local build cache and force a fresh build to confirm the cache was the problem.
rm -rf ~/.gradle/caches/build-cache-1
./gradlew clean build --no-build-cacheKey the CI cache so corruption cannot persist
Use a cache key that changes with build inputs, and avoid caching across interrupted runs.
- uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', 'gradle/wrapper/gradle-wrapper.properties') }}How to prevent it
- Avoid persisting the cache from interrupted/OOM-killed runs.
- Ensure tasks fully declare inputs/outputs so caching stays correct.
- Use a versioned cache key tied to build scripts and wrapper version.