Skip to content

Commit cfd07b0

Browse files
committed
Improve Gradle integration
1 parent 14122d0 commit cfd07b0

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public static FormatterStep create(Provisioner provisioner) {
5252

5353
/** Creates a step which apply default CleanThat mutators. */
5454
public static FormatterStep create(String version, Provisioner provisioner) {
55-
return create(MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner);
55+
return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner);
5656
}
5757

58-
public static String defaultJdkVersion() {
58+
public static String defaultSourceJdk() {
5959
// see IJdkVersionConstants.JDK_7
6060
// https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source
6161
// 1.7 is the default for 'maven-compiler-plugin' since 3.9.0
@@ -114,7 +114,7 @@ static final class JavaRefactorerState implements Serializable {
114114
final List<String> excluded;
115115

116116
JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException {
117-
this(stepName, MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner);
117+
this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner);
118118
}
119119

120120
JavaRefactorerState(String stepName,

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Added
7+
* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560))
68

79
## [6.14.1] - 2023-02-05
810
### Fixed

plugin-gradle/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
5454
- [**Quickstart**](#quickstart)
5555
- [Requirements](#requirements)
5656
- **Languages**
57-
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations))
57+
- [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat))
5858
- [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy))
5959
- [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier))
6060
- [Scala](#scala) ([scalafmt](#scalafmt))
@@ -154,6 +154,9 @@ spotless {
154154
155155
removeUnusedImports()
156156
157+
// Cleanthat will refactor your code, but it may break your style: apply it before your formatter
158+
cleanthat() // has its own section below
159+
157160
// Choose one of these formatters.
158161
googleJavaFormat() // has its own section below
159162
eclipse() // has its own section below
@@ -257,6 +260,23 @@ You can use `addTypeAnnotation()` and `removeTypeAnnotation()` to override its d
257260

258261
You can make a pull request to add new annotations to Spotless's default list.
259262

263+
### cleanthat
264+
265+
[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code. [ChangeLog](https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD)
266+
267+
```gradle
268+
spotless {
269+
java {
270+
cleanthat()
271+
// optional: you can specify a specific version and/or config file
272+
cleanthat()
273+
.groupArtifact('1.7') // default is 'io.github.solven-eu.cleanthat:java'
274+
.version('2.1') // You may force a past of -SNAPSHOT
275+
.sourceCompatibility('1.7') // default is '1.7'
276+
.addMutator('your.custom.MagicMutator')
277+
.excludeMutator('UseCollectionIsEmpty')
278+
```
279+
260280

261281
<a name="applying-to-groovy-source"></a>
262282

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public class CleanthatJavaConfig {
281281

282282
private String version = CleanthatJavaStep.defaultVersion();
283283

284-
private String sourceJdk = CleanthatJavaStep.defaultJdkVersion();
284+
private String sourceJdk = CleanthatJavaStep.defaultSourceJdk();
285285

286286
private List<String> mutators = CleanthatJavaStep.defaultMutators();
287287

@@ -305,9 +305,9 @@ public CleanthatJavaConfig version(String version) {
305305
return this;
306306
}
307307

308-
public CleanthatJavaConfig sourceJdk(String sourceJdk) {
309-
Objects.requireNonNull(sourceJdk);
310-
this.sourceJdk = sourceJdk;
308+
public CleanthatJavaConfig sourceCompatibility(String jdkVersion) {
309+
Objects.requireNonNull(jdkVersion);
310+
this.sourceJdk = jdkVersion;
311311
replaceStep(createStep());
312312
return this;
313313
}

plugin-maven/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* CleanThat Java Refactorer ([#???](https://github.com/diffplug/spotless/pull/???))
7+
* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560))
88

99
## [2.32.0] - 2023-02-05
1010
### Added

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CleanthatJava implements FormatterStepFactory {
3333

3434
// https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source
3535
@Parameter(property = "maven.compiler.source")
36-
private String sourceJdk = CleanthatJavaStep.defaultJdkVersion();
36+
private String sourceJdk = CleanthatJavaStep.defaultSourceJdk();
3737

3838
@Parameter
3939
private List<String> mutators = CleanthatJavaStep.defaultMutators();

0 commit comments

Comments
 (0)