Skip to content

Commit

Permalink
feat: Maven plugin uses CompileSourceRoots (#1847 fixes #1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Oct 9, 2023
2 parents f78cfe8 + 35b731e commit 8cdfdd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +45,15 @@ public class Java extends FormatterFactory {
public Set<String> defaultIncludes(MavenProject project) {
Path projectDir = project.getBasedir().toPath();
Build build = project.getBuild();
return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory())

List<String> 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)
Expand Down

0 comments on commit 8cdfdd0

Please sign in to comment.