Skip to content
Merged
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
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
- `expandWildcardImports()` now builds its type-solver classpath from each Java source set's compile classpath instead of every resolvable configuration. Unrelated configurations (for example generated-code or custom resolvable configs that are not ready yet) are no longer resolved. ([#2998](https://github.com/diffplug/spotless/issues/2998))
- `spotlessCheck` violation message now suggests the correct composite/included-build task path (e.g. `./gradlew :my-utils:spotlessApply`) instead of a bare `spotlessApply` / `:spotlessApply` that does not select included-build tasks. ([#2421](https://github.com/diffplug/spotless/issues/2421))
- Parallel multi-project builds no longer intermittently fail with "Cannot fingerprint input property 'stepsInternalEquality': ConfigurationCacheHackList cannot be serialized" / "Failed to provision P2 dependencies" when using `eclipse()` (or other P2-backed steps). Subprojects now share one deduping P2 provisioner and P2 queries are serialized process-wide. ([#3004](https://github.com/diffplug/spotless/issues/3004))
### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.inject.Inject;

import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

Expand Down Expand Up @@ -176,7 +175,10 @@ public void forbidModuleImports() {
public void expandWildcardImports() {
SourceSetContainer sourceSets = getSourceSets(getProject(), "expansion of wildcards requires the 'java' plugin to be applied");
Set<File> typeSolverClasspath = sourceSets.stream().flatMap(s -> s.getAllJava().getSrcDirs().stream()).collect(toSet());
getProject().getConfigurations().stream().filter(Configuration::isCanBeResolved).flatMap(c -> c.getFiles().stream()).forEach(typeSolverClasspath::add);
sourceSets.stream()
.map(SourceSet::getCompileClasspath)
.flatMap(classpath -> classpath.getFiles().stream())
.forEach(typeSolverClasspath::add);
addStep(ExpandWildcardImportsStep.create(typeSolverClasspath, provisioner()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ void expandWildCardImports() throws IOException {
assertFile("src/main/java/foo/bar/JavaCodeWildcardsUnformatted.java").sameAsResource("java/expandwildcardimports/JavaClassWithWildcardsFormatted.test");
}

@Test
void expandWildcardImportsIgnoresUnrelatedConfigurations() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'java'",
" id 'com.diffplug.spotless'",
"}",
"",
"repositories { mavenCentral() }",
"",
"configurations {",
" leftover {",
" canBeResolved = true",
" canBeConsumed = false",
" }",
"}",
"",
"dependencies {",
" leftover 'does.not:exist:1.0'",
"}",
"",
"spotless {",
" java {",
" target file('src/main/java/test.java')",
" expandWildcardImports()",
" }",
"}");
setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/java/test.java").sameAsResource("java/googlejavaformat/JavaCodeUnformatted.test");
}

/**
* Triggers the special case in {@link FormatExtension#setupTask(SpotlessTask)} with {@code toggleFence} and
* {@code targetExcludeContentPattern} both being not {@code null}.
Expand Down
Loading