Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
- Ensure `LazyForwardingEquality.unlazy()` initializes roundtrip formatter steps and their nested formatter state. ([#3211](https://github.com/diffplug/spotless/pull/3211))
- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190))

## [4.12.0] - 2026-11-21
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,6 +127,8 @@ static Object fromBytes(byte[] bytes) {
public static void unlazy(Object in) {
if (in instanceof LazyForwardingEquality<?> equality) {
equality.state();
} else if (in instanceof FormatterStepSerializationRoundtrip<?, ?> step) {
ThrowingEx.run(step::stateSupplier);
} else if (in instanceof DelegateFormatterStep step) {
unlazy(step.delegateStep);
} else if (in instanceof Iterable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.diffplug.spotless.Formatter;
import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.LazyForwardingEquality;
import com.diffplug.spotless.LineEnding;
import com.diffplug.spotless.Lint;

Expand Down Expand Up @@ -125,7 +126,10 @@ private List<FormatterStep> steps() {
}

public RoundtripAndEqualityState toEqualityState() {
return new RoundtripAndEqualityState(kind, regex(), steps(), true);
List<FormatterStep> nestedSteps = steps();
// Evaluate nested step state together with the fence.
LazyForwardingEquality.unlazy(nestedSteps);
return new RoundtripAndEqualityState(kind, regex(), nestedSteps, true);
}

public BaseFormatter toFormatterFunc() {
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
- Fix `spotlessPredeclare` with configuration cache for Maven/P2 formatter dependencies, including `googleJavaFormat()`, `greclipse()` and steps nested in `withinBlocks`, and skip provisioning for unrelated tasks. ([#2459](https://github.com/diffplug/spotless/issues/2459), [#3211](https://github.com/diffplug/spotless/pull/3211))
- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190))
- Fix `Cannot set the value of task ... property 'taskService'` when Spotless is applied to sibling projects but not to their parent, a regression since `8.3.0`. Applying it to the root project with `apply false` is no longer necessary. ([#2877](https://github.com/diffplug/spotless/issues/2877))
### Changes
Expand Down
2 changes: 2 additions & 0 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,8 @@ spotlessPredeclare {
}
```

Predeclaration initializes formatter steps that use Spotless's Maven or Eclipse P2 provisioners, including steps inside `withinBlocks`. Format configuration closures run when the task graph is ready and only when a Spotless task is scheduled. Configuration-cache hits reuse the initialized formatter state.

The older `spotless { predeclareDeps() }` and `spotless { predeclareDepsFromBuildscript() }` APIs are still supported.

If you use this feature, you will get an error if you use a formatter in a subproject which is not declared in the `spotlessPredeclare` block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
* - Gradle wants us to resolve all our dependencies in the root project - no new dependencies in subprojects
* - So, whenever a SpotlessTask in a subproject gets configured, we call {@link #hookSubprojectTask(SpotlessTask)},
* which makes this task a dependency of the SpotlessTask
* - When this "registerDependencies" task does its up-to-date check, it queries the task execution graph to see which
* SpotlessTasks are at risk of being executed, and causes them all to be evaluated safely in the root buildscript.
* - When this task is scheduled, {@link SpotlessExtensionPredeclare} resolves predeclared dependencies in its
* {@code taskGraph.whenReady} callback, before subproject Spotless tasks use them.
*/
@DisableCachingByDefault(because = "This task coordinates the setup and execution of other tasks, and should not be cached")
public abstract class RegisterDependenciesTask extends DefaultTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ public class SpotlessExtensionPredeclare extends SpotlessExtension {

public SpotlessExtensionPredeclare(Project project) {
super(project);
project.afterEvaluate(unused -> {
project.getGradle().getTaskGraph().whenReady(graph -> {
if (policy == null) {
return;
}
RegisterDependenciesTask task = registerDependenciesTask;
if (task == null) {
throw new IllegalStateException("spotlessPredeclare was enabled without a register dependencies task.");
}
if (!graph.hasTask(task)) {
return;
}
toSetup.forEach((name, formatExtension) -> {
for (Action<FormatExtension> lazyAction : formatExtension.lazyActions) {
lazyAction.execute(formatExtension);
}
task.steps.addAll(formatExtension.steps);
// needed to fix Deemon memory leaks (#1194), but this line came from https://github.com/diffplug/spotless/pull/1206
LazyForwardingEquality.unlazy(task.steps);
});
// Resolve root steps before subproject serialization and prevent daemon leaks (#1194, #1206).
LazyForwardingEquality.unlazy(task.steps);
});
}

Expand Down
Loading
Loading