diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
index 1f1c14a5e2..aa69837947 100644
--- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
+++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
@@ -79,6 +79,10 @@ public static String defaultVersion() {
return DEFAULT_VERSION;
}
+ public static String defaultStyle() {
+ return Style.DEFAULT.name();
+ }
+
static final class State implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
index e58129f5ac..0c1f0c44c8 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2020 DiffPlug
+ * Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -109,7 +109,11 @@ public class KtfmtConfig {
}
public void dropboxStyle() {
- style = Style.DROPBOX;
+ style(Style.DROPBOX);
+ }
+
+ public void style(Style style) {
+ this.style = style;
replaceStep(createStep());
}
diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
index 90b339b37a..fdc7a530c3 100644
--- a/plugin-maven/CHANGES.md
+++ b/plugin-maven/CHANGES.md
@@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Added support for eclipse-cdt 4.18.0.
* Added support for eclipse-jdt 4.18.0.
* Added support for eclipse-wtp 4.18.0.
+* Added ability to specify dropbox style for ktfmt `` ([#764](https://github.com/diffplug/spotless/pull/764))
### Changed
* Updated default eclipse-jdt from 4.17.0 to 4.18.0.
* Updated default eclipse-wtp from 4.17.0 to 4.18.0.
diff --git a/plugin-maven/README.md b/plugin-maven/README.md
index 69473075a4..de6bb61002 100644
--- a/plugin-maven/README.md
+++ b/plugin-maven/README.md
@@ -306,7 +306,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T
```xml
- 0.13
+ 0.18
+
```
diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java
index a5d99f81f4..c1258a15fe 100644
--- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java
+++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 DiffPlug
+ * Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.kotlin.KtfmtStep;
+import com.diffplug.spotless.kotlin.KtfmtStep.Style;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;
@@ -27,9 +28,13 @@ public class Ktfmt implements FormatterStepFactory {
@Parameter
private String version;
+ @Parameter
+ private String style;
+
@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
String version = this.version != null ? this.version : KtfmtStep.defaultVersion();
- return KtfmtStep.create(version, config.getProvisioner());
+ String style = this.style != null ? this.style : KtfmtStep.defaultStyle();
+ return KtfmtStep.create(version, config.getProvisioner(), Style.valueOf(style));
}
}
diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java
index 53a0d336b9..774dbf0733 100644
--- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java
+++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2020 DiffPlug
+ * Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,4 +39,16 @@ public void testKtfmt() throws Exception {
assertFile(path1).sameAsResource("kotlin/ktfmt/basic.clean");
assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean");
}
+
+ @Test
+ public void testKtfmtStyle() throws Exception {
+ // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+.
+ JreVersion.assume11OrGreater();
+
+ writePomWithKotlinSteps("");
+
+ setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/basic.dirty");
+ mavenRunner().withArguments("spotless:apply").runNoError();
+ assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean");
+ }
}