Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
- `removeUnusedImports` no longer throws on Java `import module` declarations (`JCModuleImport` ClassCastException). ([#2890](https://github.com/diffplug/spotless/issues/2890))
### Changes
- Bump default `google-java-format` version `1.28.0` -> `1.30.0` (first release with `import module` support); require at least `1.30.0` on JVM 25+.


## [4.9.0] - 2026-07-27
### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ diktat-rules = "org.cqfn.diktat:diktat-rules:1.2.5"
diktat-runner = "com.saveourtool.diktat:diktat-runner:2.0.0"
flexmark-all = "com.vladsch.flexmark:flexmark-all:0.64.8"
gherkin-utils = "io.cucumber:gherkin-utils:10.0.0"
google-java-format = "com.google.googlejavaformat:google-java-format:1.28.0"
google-java-format = "com.google.googlejavaformat:google-java-format:1.30.0"
gson = "com.google.code.gson:gson:2.14.0"
javaparser-symbol-solver-core = "com.github.javaparser:javaparser-symbol-solver-core:3.27.1"
ktfmt = "com.facebook:ktfmt:0.63"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -121,7 +121,8 @@ private static FormatterStep createInternally(String name, String groupArtifact,

private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME)
.addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898
.add(17, "1.28.0"); // default version
.addMin(25, "1.30.0") // import module (JEP 511) requires google-java-format >= 1.30.0 (https://github.com/google/google-java-format/issues/1213)
.add(17, "1.30.0"); // default version (1.30.0+ handles `import module` in RemoveUnusedImports)

public static String defaultGroupArtifact() {
return MAVEN_COORDINATE;
Expand Down
5 changes: 5 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Fixed
- `removeUnusedImports` no longer fails on Java `import module` declarations. ([#2890](https://github.com/diffplug/spotless/issues/2890))
### Changes
- Bump default `google-java-format` version `1.28.0` -> `1.30.0` (first release with `import module` support); require at least `1.30.0` on JVM 25+.


## [8.9.0] - 2026-07-27
### Added
Expand Down
5 changes: 5 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
- `removeUnusedImports` no longer fails on Java `import module` declarations. ([#2890](https://github.com/diffplug/spotless/issues/2890))
### Changes
- Bump default `google-java-format` version `1.28.0` -> `1.30.0` (first release with `import module` support); require at least `1.30.0` on JVM 25+.


## [3.9.0] - 2026-07-27
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import module java.base;
import java.util.ArrayList;
import java.util.List;

class ModuleImportTest {
void test() {
UUID.randomUUID();
List<String> list = new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import module java.base;
import java.util.ArrayList;
import java.util.List;

class ModuleImportTest {
void test() {
UUID.randomUUID();
List<String> list = new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import module java.base;
import java.util.ArrayList;
import java.util.List;

class ModuleImportWithUnused {
void test() {
UUID.randomUUID();
List<String> list = new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import module java.base;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

class ModuleImportWithUnused {
void test() {
UUID.randomUUID();
List<String> list = new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import static org.junit.jupiter.api.condition.JRE.JAVA_20;
import static org.junit.jupiter.api.condition.JRE.JAVA_21;
import static org.junit.jupiter.api.condition.JRE.JAVA_25;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
Expand Down Expand Up @@ -75,6 +76,16 @@ void versionBelowOneDotTenIsNotAllowed() throws Exception {
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 21. This requires google-java-format of at least 1.17.0 (you are using 1.9). (...)");
}


@Test
@EnabledForJreRange(min = JAVA_25)
void versionBelowMinOnJava25IsNotAllowed() throws Exception {
FormatterStep step = GoogleJavaFormatStep.create("1.28.0", "AOSP", TestProvisioner.mavenCentral());
StepHarness.forStepNoRoundtrip(step)
.expectLintsOfResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test")
.toBe("LINE_UNDEFINED google-java-format(jvm-version) You are running Spotless on JVM 25. This requires google-java-format of at least 1.30.0 (you are using 1.28.0). (...)");
}

@Test
void behaviorWithAospStyle() throws Exception {
FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), "AOSP", TestProvisioner.mavenCentral());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,8 @@
package com.diffplug.spotless.java;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.SerializableEqualityTester;
Expand All @@ -38,6 +40,20 @@ void behavior() throws Exception {
;
}

/**
* {@code import module} (JEP 511) is only parseable on JDK 25+. google-java-format 1.30+
* skips module imports in {@code RemoveUnusedImports} instead of ClassCastException on
* {@code JCModuleImport} (https://github.com/diffplug/spotless/issues/2890).
*/
@Test
@EnabledForJreRange(min = JRE.JAVA_25)
void moduleImports() throws Exception {
FormatterStep step = RemoveUnusedImportsStep.create(RemoveUnusedImportsStep.GJF, TestProvisioner.mavenCentral());
StepHarness.forStep(step)
.testResource("java/removeunusedimports/ModuleImportUnformatted.test", "java/removeunusedimports/ModuleImportFormatted.test")
.testResource("java/removeunusedimports/ModuleImportWithUnusedUnformatted.test", "java/removeunusedimports/ModuleImportWithUnusedFormatted.test");
}

@Test
void equality() throws Exception {
new SerializableEqualityTester() {
Expand Down