Gradle "Configuration cache problems found" - Causes & Fix
With the configuration cache enabled, Gradle rejects build logic that reads mutable state at execution time or captures non-serializable objects. The build reports configuration-cache problems and fails (when problems are treated as errors) - a correctness gate, not a flake.
What this error means
The build fails with N problems were found storing the configuration cache, each naming an unsupported access like invocation of 'Task.project' at execution time is unsupported or a task field that cannot be serialized.
> Configuration cache problems found in this build.
1 problem was found storing the configuration cache.
- Task `:app:myTask` of type `MyTask`: invocation of 'Task.project' at
execution time is unsupported.
See https://docs.gradle.org/current/userguide/configuration_cache.htmlDiagnose it: get the real failure out of Gradle
Gradle summarises failures aggressively, and the top-level message frequently describes a downstream symptom rather than the cause. Re-run the failing task with diagnostics before changing build logic.
# the actual stack, plus what Gradle decided about the build
./gradlew <task> --stacktrace --info
# is a stale daemon or cache involved?
./gradlew --stop
./gradlew <task> --no-daemon --no-build-cache
# what does Gradle think the environment is?
./gradlew -versionCommon causes
Reading the project model at execution time
A task action that calls project.<something> (or other live build state) during execution is unsupported - the configuration cache requires inputs to be captured at configuration time.
Capturing a non-serializable object in a task
A task that holds a reference to a non-serializable type (a Project, a Configuration, a live service) cannot be stored in the configuration cache.
How to fix it
Capture inputs at configuration time
Read the values you need into serializable properties during configuration, not in the task action.
abstract class MyTask : DefaultTask() {
@get:Input abstract val appVersion: Property<String>
@TaskAction fun run() {
// use appVersion.get(), NOT project.version at execution time
}
}
tasks.register<MyTask>("myTask") {
appVersion.set(project.version.toString()) // captured now
}Identify problems with the HTML report
Run with the configuration cache and open the report it links to find every offending access.
./gradlew build --configuration-cache
# report: build/reports/configuration-cache/<hash>/configuration-cache-report.html
# temporary unblock only:
# ./gradlew build --no-configuration-cacheConfiguration cache and CI
- The configuration cache rejects build logic that reads mutable state at execution time, which is why enabling it surfaces errors an existing build never showed.
- Run with
--configuration-cache-problems=warnfirst to see the full list rather than failing on the first one. - A cached configuration keyed to a different environment is worse than none. Include the JDK version in your cache key.
How to prevent it
- Capture task inputs into
@Input/Propertyat configuration time, never read live state in actions. - Avoid storing
Project/Configuration/services in task fields. - Run the configuration cache in CI so incompatibilities surface during development.