Skip to content

Commit 8cdfdd0

Browse files
authored
feat: Maven plugin uses CompileSourceRoots (#1847 fixes #1846)
2 parents f78cfe8 + 35b731e commit 8cdfdd0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

plugin-maven/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
### Added
8+
* 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))
9+
710
## [2.40.0] - 2023-09-28
811
### Added
912
* 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))

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import java.io.File;
2121
import java.nio.file.Path;
2222
import java.nio.file.Paths;
23+
import java.util.ArrayList;
24+
import java.util.List;
2325
import java.util.Set;
24-
import java.util.stream.Stream;
2526

2627
import org.apache.maven.model.Build;
2728
import org.apache.maven.project.MavenProject;
@@ -44,7 +45,15 @@ public class Java extends FormatterFactory {
4445
public Set<String> defaultIncludes(MavenProject project) {
4546
Path projectDir = project.getBasedir().toPath();
4647
Build build = project.getBuild();
47-
return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory())
48+
49+
List<String> includes = new ArrayList<>();
50+
includes.add(build.getSourceDirectory());
51+
includes.add(build.getTestSourceDirectory());
52+
includes.addAll(project.getCompileSourceRoots());
53+
includes.addAll(project.getTestCompileSourceRoots());
54+
55+
return includes.stream()
56+
.distinct()
4857
.map(Paths::get)
4958
.map(projectDir::relativize)
5059
.map(Java::fileMask)

0 commit comments

Comments
 (0)