Skip to content
Latchkey

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

Gradle
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

  1. Replace live-object fields with plain inputs (String, File, Provider).
  2. Resolve values at configuration time and hold the results, not the objects.
  3. Re-run so the graph serialises cleanly.
build.gradle.kts
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/Configuration in task fields.
  • Model task inputs as serializable properties and file collections.
  • Test with the configuration cache enabled before pushing.

Frequently asked questions

What causes ""cannot serialize object of type""?
The task stores a Project, Task, or Configuration in a field, which the configuration cache refuses to serialise.
How do I fix "cannot serialize object of type"?
Store only serializable values

Related guides

References

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