Gradle "Cache entry ... is corrupt" build cache in CI
Gradle read a build cache entry whose contents did not match its expected hash or length, so it discards the entry and re-runs the task. A corrupt entry usually comes from an interrupted write or a partial cache restore.
What this error means
The log shows "Cache entry '...' is corrupt. Discarding." or "Invalid cache entry", after which the task runs instead of loading FROM-CACHE.
Cache entry 'a1b2c3d4...' from the local build cache is corrupt. Discarding.
> Task :app:compileJava
Task ':app:compileJava' is not up-to-date because: Build cache entry was discarded.Common causes
An interrupted cache write
A build killed mid-store (OOM, cancelled job) left a partially written cache entry that fails validation on the next read.
A partial or mismatched cache restore
A CI cache restore that truncated files, or mixed a cache from a different Gradle version, produces entries that do not validate.
How to fix it
Clear the local build cache and re-run
- Delete the local build cache directory so corrupt entries are gone.
- Re-run; Gradle rebuilds valid entries and repopulates the cache.
- Ensure builds are not killed mid-write (bound memory).
rm -rf ~/.gradle/caches/build-cache-1
./gradlew build --no-daemonKey the cache so restores stay consistent
Include the Gradle version and lockfile hashes in the CI cache key so a restore never mixes incompatible or partial contents.
- uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ hashFiles('**/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}How to prevent it
- Include the Gradle version in the cache key.
- Bound memory so builds are not killed mid cache-write.
- Do not share a build cache across incompatible Gradle versions.