From 101c4c9e99eef71597f61b421693de42f9bf77a9 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 5 Oct 2023 09:33:49 +0800 Subject: [PATCH 1/2] feat: Maven plugin uses CompileSourceRoots Signed-off-by: tison --- .../java/com/diffplug/spotless/maven/java/Java.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index b0692446b7..e0ff14b51e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -20,8 +20,9 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import java.util.Set; -import java.util.stream.Stream; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; @@ -44,7 +45,15 @@ public class Java extends FormatterFactory { public Set defaultIncludes(MavenProject project) { Path projectDir = project.getBasedir().toPath(); Build build = project.getBuild(); - return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory()) + + List includes = new ArrayList<>(); + includes.add(build.getSourceDirectory()); + includes.add(build.getTestSourceDirectory()); + includes.addAll(project.getCompileSourceRoots()); + includes.addAll(project.getTestCompileSourceRoots()); + + return includes.stream() + .distinct() .map(Paths::get) .map(projectDir::relativize) .map(Java::fileMask) From 35b731e18ca396d1449f84925e4bb2a46ff8f6d9 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 5 Oct 2023 09:35:49 +0800 Subject: [PATCH 2/2] add CHANGELOG Signed-off-by: tison --- plugin-maven/CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1825628c73..d86096ab05 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added +* CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) + ## [2.40.0] - 2023-09-28 ### Added * Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#1782](https://github.com/diffplug/spotless/pull/1782))