Gradle configuration cache "cannot serialize object of type" in CI
The configuration cache serialises the task graph to disk. When a task field holds a reference to something not meant to be stored, like Project, Task, Gradle, or a Configuration, serialization fails and Gradle names the type it cannot store.
What this error means
The build fails storing the configuration cache with "cannot serialize object of type 'org.gradle.api.Project', a subtype of 'org.gradle.api.Task.project', as these are not supported".
1 problem was found storing the configuration cache.
- Task `:app:myTask` of type `MyTask`: cannot serialize object of type
'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project',
as these are not supported with the configuration cache.Common causes
A task field references a live build object
The task stores a Project, Task, or Configuration in a field, which the configuration cache refuses to serialise.
A closure captures build state
A lambda or Groovy closure implicitly captures project or another live object, dragging it into the serialised graph.
How to fix it
Store only serializable values
- Replace live-object fields with plain inputs (String, File, Provider).
- Resolve values at configuration time and hold the results, not the objects.
- Re-run so the graph serialises cleanly.
abstract class MyTask : DefaultTask() {
@get:InputFiles abstract val classpath: ConfigurableFileCollection
// hold a FileCollection, not the Configuration object
}Avoid capturing project in closures
Pull the value you need out of project at configuration time and reference the value, so the closure does not capture the live project.
How to prevent it
- Never store
Project/Task/Configurationin task fields. - Model task inputs as serializable properties and file collections.
- Test with the configuration cache enabled before pushing.