Compatibility considerations for the IDE hook. #1103
Draft
+20
−0
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 Spotless IDE hook should just be
spotlessApply -PspotlessIdeHook=${ABSOLUTE_PATH_TO_FILE}
. We've had this API since3.30.0
, and you shouldn't have to parse a Gradle or Spotless version to use it.But we've got two backward incompatible problems:
Spotless IDE hook is not compatible with the configuration-cache, so you have to specify
--no-configuration-cache
. But, that flag is not compatible with Gradle < 6.6. So you're stuck in this position where you have to parse the Gradle version to know whether you need that flag or not.We can speed Spotless up a lot by changing the API to
:spotlessApply -PspotlessIdeHook=BLAH
, but only after faster -PspotlessIdeHook with configure-on-demand #1101 gets implemented. So you're stuck in this position where you have to parse the Spotless version to know whether you can add the leading colon or not.We could fix both of those issues by changing the API to this:
:spotlessIdeHook -PspotlessIdeHook=BLAH --configure-on-demand
This fixes problem 1 because Gradle 7.4 adds a new
Task.notCompatibleWithConfigurationCache()
method. We can't use that method to fix problem 1 forspotlessApply
, but we could use it to fix a new task calledspotlessIdeHook
.It also fixes problem 2 because we can change the implementation of
:spotlessIdeHook
over time. At first it would trigger the evaluation of all subprojects (likespotlessApply
does now), but later on it could take advantage of configure-on-demand to speed up execution dramatically.So I have a question for each of you, @badsyntax and @ragurney, which is easier?
A) Parse Gradle and Spotless versions to determine which arguments to use.
B) Optimistically try
:spotlessIdeHook
method, if it fails fall back tospotlessApply
, and then remember "optimistic attempt failed" for the rest of the plugin's runtime. No parsing needed, just detecting an error.As an aside, Spotless is adding support for linters in the medium-term future, and those lints will be available in the IDE hook. We are able to add this information in a backward-compatible way, so it will be optional whether you choose to add support for that in future, no version-parsing or feature-detection required.