Execute the configuration actions lazily #618
Merged
+36
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The only substantive change is that instead of this in the legacy
SpotlessExtension
...spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionBase.java
Lines 203 to 206 in 1e2801d
...we add a field to
FormatExtension
, and populate it in each call toSpotlessExtension::format(name, clazz, action)
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
Line 60 in 1e2801d
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionModern.java
Lines 52 to 54 in 1e2801d
Instead of executing the closures when they are declared, we store them, and only execute them when the task is configured:
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionModern.java
Lines 70 to 79 in 1e2801d
In my head, I thought that we would be able to remove the
afterEvaluate
block, but now I see that it was a mirage. If someone eagerly creates the task, and then callsjava { blah }
, it's important for thatblah
to have effect, but it wouldn't if you don't do theafterEvaluate
.It seems to me that this is as lazy as it could possibly be - we don't describe any of the properties of a task, or even execute the code that describes those those properties, until/unless that task is being configured. It also seems to me like it's quite difficult to avoid the
afterEvaluate
, which I guess is the point of theProvider<>
stuff. We could changeFormatExtension
so that it applied itself directly against theSpotlessTask
, rather than storing its own field forencoding
, etc. The only hard part against that is cases where a user setsUTF-8
at the level of the Spotless block, but has some legacy subproject where encoding isCP-1252
, cases like that.Is
afterEvaluate
in any long-term trouble? Whaddya think @bigdaz?