Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

Your team set up a remote Gradle build cache but CI hit rates stay below 20 percent. What causes cache misses and how do you investigate?

A cache miss means some task input hashed differently from every earlier build, so the usual causes are inputs that differ per machine or per run: absolute paths in file inputs, different JDK vendors or versions, different line endings between operating systems, and volatile values such as build timestamps or commit ids baked into generated resources. We investigate by comparing the input hashes of the same task in two builds, using build scans or -Dorg.gradle.caching.debug=true, and fixing each difference at its source. We also check the setup: usually only CI should write to the remote cache, and developers only read from it.

Why this question is asked

A remote build cache promises that a task built once is never built again anywhere. When the hit rate stays below 20 percent, the team pays for the cache, uploads gigabytes of entries, and gets almost nothing back. The cause is almost never the cache server itself; it is task inputs that are not as stable as everyone assumed. Interviewers ask this debugging question because the investigation shows whether we understand what goes into a cache key. In this answer, we will recap how a key is built, go through the common causes of misses one by one with their fixes, then see a step-by-step way to find the culprit and how to set up push and pull roles.

1A Quick Recap of Cache Keys

For each cacheable task, Gradle computes a cache key: a hash built from the task's type and implementation, every input property's value, and a fingerprint of every input file. A file fingerprint covers the file's content and, depending on the path sensitivity, its path. If two builds on different machines produce the same key, the second one can download the first one's outputs and print FROM-CACHE.

So a miss always means that one or more of those ingredients differed. With a hit rate below 20 percent, something is differing on almost every build, and because tasks depend on each other, one early difference spreads: if compileJava misses, its output classes are a new input for test, jar and everything after it, so they miss too. Finding the first differing task usually explains most of the misses.

2Cause 1: Absolute Paths in Inputs

The default path sensitivity for file inputs of a custom task is ABSOLUTE, so the full path is part of the key. CI agents often check out code into directories such as /builds/agent-14/workspace/shop-7f3a, which changes from agent to agent, so the same file has a different fingerprint on each one.

Java
// Misses on every agent: absolute path is part of the key
@get:InputFiles abstract val templates: ConfigurableFileCollection
// Hits across agents: only the path inside the project matters
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val templates: ConfigurableFileCollection
// Another common leak: an absolute path passed as a plain string input
// args.add(project.projectDir.absolutePath) // /builds/agent-14/... in the key

Built-in Gradle tasks already use sensible path sensitivity, so this cause usually hides in custom tasks and in third-party plugins. Notice the second leak: an absolute path passed as a string, for example in compiler arguments or a system property for tests, ends up in the key just the same. Those values should be passed as file inputs with relative sensitivity, or as @Internal if they do not affect the outputs.

3Cause 2: Different JDKs and Line Endings

The JDK used to compile and test is part of the inputs of JavaCompile and Test, because a different compiler can produce different classes. If some agents run Temurin 25.0.1 and others a different vendor or patch release, their keys differ even for identical sources. Using Gradle toolchains with a fixed language version and vendor, and the same JDK distribution on every agent, removes that difference.

Line endings are the other classic. A Windows checkout with Git's autocrlf setting turns LF into CRLF, so every text file has different bytes, and every task that reads source files misses. Pinning line endings in a .gitattributes file, such as * text=auto eol=lf, fixes the files themselves. For custom tasks, Gradle also offers @NormalizeLineEndings on file inputs so that line endings are ignored in the fingerprint; check your Gradle version for its availability.

4Cause 3: Volatile Values in Generated Resources

Many builds write a small file with build information into the jar: the build time, the git commit, the CI build number. Each of these is new on every build or every commit. The file is an input to processResources, which feeds the runtime classpath, which is an input to every test task. So one timestamp can make every Test task miss, and tests are usually the most expensive tasks to rerun.

Java
// Spring Boot's build info: drop the time, which changes every build
springBoot {
buildInfo {
excludes = setOf("time")
}
}
// Or tell Gradle to ignore the file when fingerprinting the runtime classpath
normalization {
runtimeClasspath {
ignore("META-INF/build-info.properties")
}
}

The first option removes the volatile value. The second keeps it in the jar but tells Gradle to ignore that file when fingerprinting runtime classpaths, so tests can still hit the cache. Notice that a commit id is less harmful than a timestamp, because it changes only when the code changes, but it still makes every commit a full miss for tasks downstream of it, which defeats most of the cache's value on pull request builds.

5Finding the Culprit Step by Step

We do not guess. We take two builds that should have produced the same keys, for example the same commit built on two agents, and compare the inputs of the first task that missed.

With Develocity build scans, the comparison view shows, for each task, which input property or file had a different hash. Without build scans, the caching debug flag makes Gradle log the hash of every input of every task, and a plain diff of the two logs points at the difference.

YAML
# on two agents, same commit
./gradlew build --build-cache -Dorg.gradle.caching.debug=true > agent-a.log
./gradlew build --build-cache -Dorg.gradle.caching.debug=true > agent-b.log
# shortened lines from the logs
# Appending inputPropertyHash for 'templates' to build cache key: 8f2c... (agent-a)
# Appending inputPropertyHash for 'templates' to build cache key: 1d9e... (agent-b)
# Build cache key for task ':core:generateConfig' is 4b71...
diff <(grep generateConfig agent-a.log) <(grep generateConfig agent-b.log)
Step throughInvestigating low cache hit rates
  1. Pick two builds that should matchsame commit, two agents
  2. Find the first task that missedearliest in the task graph
  3. Compare its input hashesbuild scan comparison or caching.debug logs
  4. Which input differs?
    YesFix it at the sourceNoCheck task implementation and classpath
  5. Rerun and measure the hit raterepeat for the next task

5 steps in order. Play them, or step through them one at a time.

Notice the order of work: start from the earliest task in the build that misses, because its changed output explains the misses after it. Fix one cause, rerun the comparison, and move to the next. The exact log wording can differ between Gradle versions, but the property names it prints are the ones we need.

6Who Writes and Who Reads the Remote Cache

Finally, the setup itself. If every developer machine pushes to the remote cache, entries built with local changes, odd JDKs or uncommitted files fill it up, evicting useful entries and, in the worst case, serving surprising outputs. The usual pattern is that CI, a controlled environment, pushes, and developers only pull.

Java
// settings.gradle.kts
buildCache {
local { isEnabled = true }
remote<HttpBuildCache> {
url = uri("https://gradle-cache.internal.example.com/cache/")
isPush = System.getenv("CI") == "true" // only CI writes
}
}

Also check that the cache is big enough to hold a day or two of entries for all branches; a cache that evicts entries within hours will show low hit rates for reasons that have nothing to do with inputs.

7Follow-up questions

How do I measure the hit rate correctly?

Count only cacheable tasks, and measure the share that were FROM-CACHE or UP-TO-DATE out of all cacheable tasks that were requested. Build scans report this per build. A rate that only counts all tasks is misleading, because non-cacheable tasks such as Jar can never hit.

Why does a change in a plugin version make everything miss?

The task's implementation, including the classes of the plugin that defines it, is part of the key. Upgrading a plugin or Gradle itself changes the implementation hash, so the first build after the upgrade misses for every affected task. That is expected and recovers once CI has pushed new entries.

Can annotation processors cause misses?

Yes. The annotation processor path is an input to JavaCompile, and some processors generate code with timestamps or absolute paths, or read undeclared files. If compileJava misses even with identical sources and JDKs, compare the processor path and the generated sources between two builds.

8Conclusion

In this answer, we saw that a cache key is a hash of a task's implementation, input values and file fingerprints, so any input that differs between machines or runs causes a miss that spreads downstream. The common causes are absolute path sensitivity, different JDK vendors or versions, different line endings, and volatile values such as timestamps and commit ids in generated resources. We find them by comparing input hashes of the first missing task in two builds, with build scans or -Dorg.gradle.caching.debug=true, and we let only CI push to the remote cache while developers read from it.

What to say in the interviewAbout 90 seconds aloud

Open with

A miss means the cache key differed, and the key is a hash of the task's implementation, its input values and fingerprints of its input files. So with hit rates under 20 percent I assume something varies on almost every build, and since outputs feed later tasks, one early miss spreads to everything downstream.

Then, if they want more

The usual suspects are four. Absolute paths: custom tasks default to absolute path sensitivity, and CI agents check out into different directories, so I switch file inputs to relative. Toolchains: a different JDK vendor or patch version changes compile and test inputs, so I pin toolchains and use one distribution.

Line endings: Windows checkouts with CRLF change every source file, so I set them in gitattributes. And volatile values: build timestamps or commit ids in generated resources like build-info change the runtime classpath, so every test task misses; I drop the time or use runtime classpath normalization to ignore that file.

To find the real cause I compare two builds of the same commit, either with a build scan comparison or by running with org.gradle.caching.debug set to true, which logs each input hash, then diff the first task that missed. I fix one cause at a time and remeasure.

And I check the setup: only CI should push to the remote cache, developers just read, and the cache has to be big enough not to evict entries within hours.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Gradle user manual
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your team set up a remote Gradle build cache but CI hit rates stay below 20 percent....": https://scrivio-interview-library.netlify.app/java/gradle/e11e00c568/