Separate the core SpotlessTask from check and apply#576
Merged
nedtwigg merged 15 commits intodiffplug:masterfrom May 14, 2020
bigdaz:dd/incremental
Merged
Separate the core SpotlessTask from check and apply#576nedtwigg merged 15 commits intodiffplug:masterfrom bigdaz:dd/incremental
SpotlessTask from check and apply#576nedtwigg merged 15 commits intodiffplug:masterfrom
bigdaz:dd/incremental
Conversation
With this change, the Spotless Gradle plugin will leverage more of the
core Gradle functionality for incremental builds, thus avoiding some
of the complication present in the previous implementation.
- SpotlessTask runs the formatter for each source file, and generates the
formatted file into a designated output directory (if format is required)
- If the task is not incremental, all prior outputs are removed
- For each added file, the formatter is run, and the output is
written if different from the original
- For each removed file, the previous output is removed, if present
- SpotlessCheck takes as input the output directory of the SpotlessTask,
and will fail if any outputs are present
- SpotlessApply will copy any formatted outputs back over the original source
This mechanism has a number of benefits and makes things a lot simpler:
- The spotless cache is not required
- SpotlessTask is now a simple incremental task and benefits from the
usual up-to-date checking. It should also support being made cacheable.
At this stage, SpotlessCheck does not produce informative error messages
on failure.
For each file output by the format task, the check task generates a failure message. This simle implementation is not particularly efficient as it involves re-running the formatter against the original source file rather than comparing the source with the formatted output. However, in the regular case where 'spotlessCheck' will pass, this inefficiency will have no impact.
In order to maintain existing behaviour for 'spotlessCheck' and 'spotlessApply', the UP-TO-DATE state of these tasks will be based on the state of the matching SpotlessTask. While this is a bit of a hack, it gets the tests passing and this behaviour can be revisited at a later date.
This test demonstrates that fewer format operations are required to retain the existing incremental behaviour.
Member
|
Amazing!! Thanks so much. I gave it a careful readthrough, and the only thing left before merging is the changelog and fixing up All of these benefits are definitely worth this small breaking change. I also think I'll do some integration testing with this tomorrow and take a stab at the changelog. |
3 tasks
Member
|
Woo! Happy to see this merged in. Thank you very much @bigdaz. 👍 |
Member
|
Released in plugin-gradle |
This was referenced May 26, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With this change, the Spotless Gradle plugin will leverage more of the
core Gradle functionality for incremental builds, thus avoiding some
of the complication present in the previous implementation.
formatted file into a designated output directory (if format is required)
written if different from the original
and will fail if any outputs are present
This mechanism has a number of benefits and makes things a lot simpler:
usual up-to-date checking. It should also support being made cacheable.