Skip to content
Latchkey

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.

Gradle
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

  1. Delete the local build cache directory so corrupt entries are gone.
  2. Re-run; Gradle rebuilds valid entries and repopulates the cache.
  3. Ensure builds are not killed mid-write (bound memory).
Terminal
rm -rf ~/.gradle/caches/build-cache-1
./gradlew build --no-daemon

Key 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.

.github/workflows/ci.yml
- 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.

Frequently asked questions

What causes ""is corrupt. Discarding.""?
A build killed mid-store (OOM, cancelled job) left a partially written cache entry that fails validation on the next read.
How do I fix "is corrupt. Discarding."?
Clear the local build cache and re-run

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card