diff --git a/CHANGES.md b/CHANGES.md
index 2f9e031795..735eca7576 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,7 +13,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
-* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
### Fixed
* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
@@ -418,8 +417,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [2.26.0] - 2022-06-05
### Added
* Support for `editorConfigOverride` in `ktlint`. ([#1218](https://github.com/diffplug/spotless/pull/1218) fixes [#1193](https://github.com/diffplug/spotless/issues/1193))
-### Fixed
-* `google-java-format` and `RemoveUnusedImportsStep` works on JDK16+ without jvm args workaround. ([#1224](https://github.com/diffplug/spotless/pull/1224) fixes [#834](https://github.com/diffplug/spotless/issues/834))
## [2.25.3] - 2022-05-10
### Fixed
diff --git a/lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java b/lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java
index fcdb52503b..71b6dc4281 100644
--- a/lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java
+++ b/lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java
@@ -22,12 +22,12 @@
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.Provisioner;
-/** Uses palantir-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
+/** Uses google-java-format or cleanthat.UnnecessaryImport, but only to remove unused imports. */
public class RemoveUnusedImportsStep implements Serializable {
private static final long serialVersionUID = 1L;
static final String NAME = "removeUnusedImports";
- static final String DEFAULT_FORMATTER = "palantir-java-format";
+ static final String GJF = "google-java-format";
static final String CLEANTHAT = "cleanthat-javaparser-unnecessaryimport";
// https://github.com/solven-eu/cleanthat/blob/master/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java
@@ -37,17 +37,18 @@ public class RemoveUnusedImportsStep implements Serializable {
private RemoveUnusedImportsStep() {}
public static String defaultFormatter() {
- return DEFAULT_FORMATTER;
+ return GJF;
}
public static FormatterStep create(Provisioner provisioner) {
- return create(DEFAULT_FORMATTER, provisioner);
+ // The default importRemover is GJF
+ return create(GJF, provisioner);
}
public static FormatterStep create(String unusedImportRemover, Provisioner provisioner) {
Objects.requireNonNull(provisioner, "provisioner");
switch (unusedImportRemover) {
- case DEFAULT_FORMATTER:
+ case GJF:
return GoogleJavaFormatStep.createRemoveUnusedImportsOnly(provisioner);
case CLEANTHAT:
return CleanthatJavaStep.createWithStepName(NAME, CleanthatJavaStep.defaultGroupArtifact(), CleanthatJavaStep.defaultVersion(), "99.9", List.of(CLEANTHAT_MUTATOR), List.of(), false, provisioner);
diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java
deleted file mode 100644
index 85713423cc..0000000000
--- a/plugin-maven/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2016-2025 DiffPlug
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.diffplug.spotless.java;
-
-import static com.diffplug.spotless.java.RemoveUnusedImportsStep.DEFAULT_FORMATTER;
-import static com.diffplug.spotless.java.RemoveUnusedImportsStep.NAME;
-import static com.diffplug.spotless.java.RemoveUnusedImportsStep.defaultFormatter;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import java.util.Collections;
-
-import org.junit.jupiter.api.Test;
-
-import com.diffplug.spotless.maven.MavenIntegrationHarness;
-
-class RemoveUnusedImportsStepTest extends MavenIntegrationHarness {
-
- @Test
- void testRemoveUnusedImports() throws Exception {
- writePomWithJavaSteps("");
-
- String path = "src/main/java/test.java";
- setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
- mavenRunner().withArguments("spotless:apply").runNoError();
- assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
- }
-
- @Test
- void testDefaults() {
- assertEquals("palantir-java-format", defaultFormatter());
- assertEquals("palantir-java-format", DEFAULT_FORMATTER);
- assertEquals("removeUnusedImports", NAME);
- }
-
- @Test
- void testCreateWithDefaultFormatter() {
- assertEquals(NAME, RemoveUnusedImportsStep.create((groupArtifact, version) -> Collections.emptySet()).getName());
- }
-
- @Test
- void testCreateWithPalantirFormatter() {
- assertEquals(NAME, RemoveUnusedImportsStep.create("palantir-java-format", (groupArtifact, version) -> Collections.emptySet()).getName());
- }
-
- @Test
- void testCreateWithCleanthatFormatter() {
- assertEquals(NAME, RemoveUnusedImportsStep.create("cleanthat-javaparser-unnecessaryimport", (groupArtifact, version) -> Collections.emptySet()).getName());
- }
-
- @Test
- void testCreateWithInvalidFormatter() {
- assertThrows(IllegalArgumentException.class, () -> RemoveUnusedImportsStep.create("invalid-formatter", (groupArtifact, version) -> Collections.emptySet()));
- }
-
- @Test
- void testCreateWithNullProvisioner() {
- assertThrows(NullPointerException.class, () -> RemoveUnusedImportsStep.create("palantir-java-format", null));
- }
-}
diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java
new file mode 100644
index 0000000000..3689fa8f98
--- /dev/null
+++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveUnusedImportsStepTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2016-2025 DiffPlug
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.diffplug.spotless.maven.java;
+
+import org.junit.jupiter.api.Test;
+
+import com.diffplug.spotless.maven.MavenIntegrationHarness;
+
+class RemoveUnusedImportsStepTest extends MavenIntegrationHarness {
+
+ @Test
+ void testRemoveUnusedInports() throws Exception {
+ writePomWithJavaSteps("");
+
+ String path = "src/main/java/test.java";
+ setFile(path).toResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test");
+ mavenRunner().withArguments("spotless:apply").runNoError();
+ assertFile(path).sameAsResource("java/removeunusedimports/JavaCodeWithPackageFormatted.test");
+ }
+}
diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java
index 766816a659..84ad3f1f61 100644
--- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java
+++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java
@@ -25,7 +25,7 @@
class RemoveUnusedImportsStep_withGoogleJavaFormatTest {
@Test
void behavior() throws Exception {
- FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
+ FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
StepHarness.forStep(step)
.testResource("java/removeunusedimports/JavaCodeUnformatted.test", "java/removeunusedimports/JavaCodeFormatted.test")
.testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test")
@@ -48,7 +48,7 @@ protected void setupTest(API api) {
@Override
protected FormatterStep create() {
- return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.DEFAULT_FORMATTER, TestProvisioner.mavenCentral());
+ return RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
}
}.testEquals();
}