Repository navigation
Description
What happens
With the configuration cache on (--configuration-cache, or org.gradle.configuration-cache=true), two of the Gradle plugin's tasks fail. Reproduced with Gradle 9.3.1, Spotless 8.10.4 and JDK 21, with the plugin built from 21.X.X, whose sources are unchanged since 21.0.1.
formatDiff, with the Java-based and the native formatter alike:
> Task :formatDiff FAILED
1 problem was found storing the configuration cache.
- Task `:formatDiff` of type `com.palantir.javaformat.gradle.PalantirJavaFormatPlugin$FormatDiffTask`: invocation of 'Task.project' at execution time is unsupported with the configuration cache.
The entry is discarded, so every run fails the same way.
spotlessCheck and spotlessApply, with com.diffplug.spotless applied: every file gets a lint error and the task fails.
> Task :spotlessJavaCheck FAILED
> There were 1 lint error(s), they must be fixed or suppressed.
src/main/java/Foo.java:LINE_UNDEFINED open-java-format(java.lang.NullPointerException) Cannot invoke "java.util.function.Supplier.get()" because "this.jarsSupplier" is null (...)
The next run does not reuse the entry either: configuration cache cannot be reused because an input to unknown location has changed. In the same project without the open-java-format step, Spotless stores its entry and reuses it.
The IntelliJ tasks (updateOpenJavaFormatXml, updateWorkspaceXml, updateExternalDependenciesXml) work: their entry is stored and reused. Gradle turns the cache off when its own idea task runs, which is not compatible with it; that is not the plugin's doing.
Why
FormatDiffTask.formatDiff()callsgetProject()when it runs, for the project directory and for the root project'sJavaFormatExtension, which loads the formatter.PalantirJavaFormatStep.Statekeeps the formatter jars and the loadedFormatterServiceintransientfields. The configuration cache serializes the Spotless step, and the step it reads back has both fieldsnull, on the run that stores the entry too.
SupportsCurrentSpotlessTest, the only plugin test with the cache on, runs classes: it creates the Spotless step but never formats with it. Every other plugin test runs with the cache off.
Proposal
formatDiffgets what it needs as task properties set at configuration time, the project directory and the formatter classpath, and loads the formatter when it runs, withoutProject.- The Spotless step keeps state that survives serialization: the formatter jar files, from which the formatter is loaded on first use. The jars stay an input, so another formatter version still makes
spotlessJavaout of date. - Tests run
formatDiff,spotlessApply,spotlessCheckand the IntelliJ tasks twice with the cache on, and check that the first run stores the entry and the second reuses it.
Until then
Run these tasks with --no-configuration-cache, or set org.gradle.configuration-cache=false in the project's gradle.properties.
Activity