Separate the core `SpotlessTask` from check and apply by bigdaz · Pull Request #576 · diffplug/spotless

added 8 commits

May 12, 2020 21:31
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.

@nedtwigg

This was referenced

May 26, 2020

@bigdaz bigdaz deleted the dd/incremental branch

June 8, 2020 16:48