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
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Added
- Add support for custom string format for license header copyright year via `yearStringFormat()`. ([#2965](https://github.com/diffplug/spotless/pull/2965))
### Fixed
- `<expandWildcardImports>` no longer triggers a full transitive dependency resolution on every build. Dependency resolution is now deferred until the step actually runs, so projects that do not use `<expandWildcardImports>` (or that use version ranges) are no longer penalized. ([#2983](https://github.com/diffplug/spotless/issues/2983))

## [3.7.0] - 2026-06-16
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ private FormatterConfig getFormatterConfig() {
final Optional<String> userRatchetFrom = Optional.ofNullable((String) mavenSession.getUserProperties().get("ratchetFrom"));
final Optional<String> optionalRatchetFrom = Optional.ofNullable(this.ratchetFrom)
.filter(ratchet -> !RATCHETFROM_NONE.equals(ratchet));
Optional<Set<File>> projectClasspath = computeTypeSolverClasspath(resolver);
return new FormatterConfig(baseDir, encoding, lineEndings, userRatchetFrom, optionalRatchetFrom, provisioner, p2Provisioner, fileLocator, formatterStepFactories, Optional.ofNullable(setLicenseHeaderYearsFromGitHistory), lintSuppressions, projectClasspath);
// Lazy: only resolve dependencies when the expandWildcardImports step actually requests the classpath.
Supplier<Set<File>> projectClasspathSupplier = () -> computeTypeSolverClasspath(resolver);
return new FormatterConfig(baseDir, encoding, lineEndings, userRatchetFrom, optionalRatchetFrom, provisioner, p2Provisioner, fileLocator, formatterStepFactories, Optional.ofNullable(setLicenseHeaderYearsFromGitHistory), lintSuppressions, Optional.of(projectClasspathSupplier));
}

private Optional<Set<File>> computeTypeSolverClasspath(ArtifactResolver resolver) {
private Set<File> computeTypeSolverClasspath(ArtifactResolver resolver) {
Set<File> classpath = new LinkedHashSet<>();

// Add source roots (directories containing .java files for JavaParserTypeSolver)
Expand All @@ -446,7 +447,7 @@ private Optional<Set<File>> computeTypeSolverClasspath(ArtifactResolver resolver
getLog().warn("Could not resolve project dependencies for expandWildcardImports: " + e.getMessage());
}

return Optional.of(classpath);
return classpath;
}

private FileLocator getFileLocator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import com.diffplug.spotless.LineEnding;
import com.diffplug.spotless.LintSuppression;
Expand All @@ -39,10 +40,10 @@ public class FormatterConfig {
private final List<FormatterStepFactory> globalStepFactories;
private final Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory;
private final List<LintSuppression> lintSuppressions;
private final Optional<Set<File>> projectClasspath;
private final Optional<Supplier<Set<File>>> projectClasspathSupplier;

public FormatterConfig(File baseDir, String encoding, LineEnding lineEndings, Optional<String> userRatchetFrom, Optional<String> ratchetFrom, Provisioner provisioner,
P2Provisioner p2Provisioner, FileLocator fileLocator, List<FormatterStepFactory> globalStepFactories, Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory, List<LintSuppression> lintSuppressions, Optional<Set<File>> projectClasspath) {
P2Provisioner p2Provisioner, FileLocator fileLocator, List<FormatterStepFactory> globalStepFactories, Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory, List<LintSuppression> lintSuppressions, Optional<Supplier<Set<File>>> projectClasspathSupplier) {
this.encoding = encoding;
this.lineEndings = lineEndings;
this.userRatchetFrom = userRatchetFrom;
Expand All @@ -53,7 +54,7 @@ public FormatterConfig(File baseDir, String encoding, LineEnding lineEndings, Op
this.globalStepFactories = globalStepFactories;
this.spotlessSetLicenseHeaderYearsFromGitHistory = spotlessSetLicenseHeaderYearsFromGitHistory;
this.lintSuppressions = lintSuppressions;
this.projectClasspath = projectClasspath;
this.projectClasspathSupplier = projectClasspathSupplier;
}

public String getEncoding() {
Expand Down Expand Up @@ -96,7 +97,7 @@ public List<LintSuppression> getLintSuppressions() {
return unmodifiableList(lintSuppressions);
}

public Optional<Set<File>> getProjectClasspath() {
return projectClasspath;
public Optional<Supplier<Set<File>>> getProjectClasspathSupplier() {
return projectClasspathSupplier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private Optional<String> optionalRatchetFrom() {
}

private FormatterStepConfig stepConfig(Charset encoding, FormatterConfig config) {
return new FormatterStepConfig(encoding, licenseHeaderDelimiter(), ratchetFrom(config), config.getProvisioner(), config.getP2Provisioner(), config.getFileLocator(), config.getSpotlessSetLicenseHeaderYearsFromGitHistory(), config.getProjectClasspath());
return new FormatterStepConfig(encoding, licenseHeaderDelimiter(), ratchetFrom(config), config.getProvisioner(), config.getP2Provisioner(), config.getFileLocator(), config.getSpotlessSetLicenseHeaderYearsFromGitHistory(), config.getProjectClasspathSupplier());
}

private static List<FormatterStepFactory> gatherStepFactories(List<FormatterStepFactory> allGlobal, List<FormatterStepFactory> allConfigured) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.charset.Charset;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.extra.P2Provisioner;
Expand All @@ -32,17 +33,17 @@ public class FormatterStepConfig {
private final P2Provisioner p2Provisioner;
private final FileLocator fileLocator;
private final Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory;
private final Optional<Set<File>> projectClasspath;
private final Optional<Supplier<Set<File>>> projectClasspathSupplier;

public FormatterStepConfig(Charset encoding, String licenseHeaderDelimiter, Optional<String> ratchetFrom, Provisioner provisioner, P2Provisioner p2Provisioner, FileLocator fileLocator, Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory, Optional<Set<File>> projectClasspath) {
public FormatterStepConfig(Charset encoding, String licenseHeaderDelimiter, Optional<String> ratchetFrom, Provisioner provisioner, P2Provisioner p2Provisioner, FileLocator fileLocator, Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory, Optional<Supplier<Set<File>>> projectClasspathSupplier) {
this.encoding = encoding;
this.licenseHeaderDelimiter = licenseHeaderDelimiter;
this.ratchetFrom = ratchetFrom;
this.provisioner = provisioner;
this.p2Provisioner = p2Provisioner;
this.fileLocator = fileLocator;
this.spotlessSetLicenseHeaderYearsFromGitHistory = spotlessSetLicenseHeaderYearsFromGitHistory;
this.projectClasspath = projectClasspath;
this.projectClasspathSupplier = projectClasspathSupplier;
}

public Charset getEncoding() {
Expand Down Expand Up @@ -73,7 +74,7 @@ public Optional<String> spotlessSetLicenseHeaderYearsFromGitHistory() {
return spotlessSetLicenseHeaderYearsFromGitHistory;
}

public Optional<Set<File>> getProjectClasspath() {
return projectClasspath;
public Optional<Supplier<Set<File>>> getProjectClasspathSupplier() {
return projectClasspathSupplier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.util.Collections;
import java.util.Set;
import java.util.function.Supplier;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.java.ExpandWildcardImportsStep;
Expand All @@ -27,7 +28,9 @@
public class ExpandWildcardImports implements FormatterStepFactory {
@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
Set<File> classpath = config.getProjectClasspath().orElse(Collections.emptySet());
Set<File> classpath = config.getProjectClasspathSupplier()
.map(Supplier::get)
.orElse(Collections.emptySet());
return ExpandWildcardImportsStep.create(classpath, config.getProvisioner());
}
}
Loading