Skip to content

fix: make ApiSpecTask compatible with Gradle Configuration Cache#297

Open
grubmeshi wants to merge 1 commit intoePages-de:masterfrom
grubmeshi:fix/configuration-cache-support
Open

fix: make ApiSpecTask compatible with Gradle Configuration Cache#297
grubmeshi wants to merge 1 commit intoePages-de:masterfrom
grubmeshi:fix/configuration-cache-support

Conversation

@grubmeshi
Copy link
Copy Markdown

Summary

Move objectMapper instantiation from a task instance field into the @TaskAction method to make OpenApi3Task, OpenApiTask, and PostmanTask compatible with Gradle's Configuration Cache.

Problem

Jackson's ObjectMapper contains non-serializable fields (StdDateFormat, ReentrantLock) that prevent Gradle from serializing the task graph into the configuration cache. This causes:

Configuration cache state could not be cached: field `_dateFormat` of
`com.fasterxml.jackson.databind.cfg.BaseSettings` bean found in field `objectMapper`
of task `:generateOpenApi3Raw` of type `com.epages.restdocs.apispec.gradle.OpenApi3Task`:
error writing value of type 'com.fasterxml.jackson.databind.util.StdDateFormat'

Every build that includes these tasks gets its configuration cache entry discarded, negating any caching benefit.

Fix

Since objectMapper is only used inside aggregateResourceModels(), it does not need to be a persistent field on the task instance. Moving it to a local variable inside the @TaskAction method avoids the serialization issue entirely.

Fixes #284

Move objectMapper instantiation from a task instance field into the
@TaskAction method. Jackson's ObjectMapper contains non-serializable
fields (StdDateFormat, ReentrantLock) that prevent Gradle from caching
the task graph, causing 'configuration cache entry discarded' on every
build that includes OpenApi3Task, OpenApiTask, or PostmanTask.

Since objectMapper is only used inside aggregateResourceModels(), it
does not need to be a persistent field on the task instance.

Fixes ePages-de#284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for gradle configuration cache

1 participant