diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java index a41b6de687c..75b960507ac 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java @@ -23,7 +23,6 @@ import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.ResolvableDependencies; import org.gradle.util.GradleVersion; import org.springframework.boot.gradle.dsl.SpringBootExtension; @@ -91,7 +90,6 @@ public class SpringBootPlugin implements Plugin { createExtension(project); Configuration bootArchives = createBootArchivesConfiguration(project); registerPluginActions(project, bootArchives); - unregisterUnresolvedDependenciesAnalyzer(project); } private void verifyGradleVersion() { @@ -128,18 +126,4 @@ public class SpringBootPlugin implements Plugin { } } - private void unregisterUnresolvedDependenciesAnalyzer(Project project) { - UnresolvedDependenciesAnalyzer unresolvedDependenciesAnalyzer = new UnresolvedDependenciesAnalyzer(); - project.getConfigurations().all((configuration) -> { - ResolvableDependencies incoming = configuration.getIncoming(); - incoming.afterResolve((resolvableDependencies) -> { - if (incoming.equals(resolvableDependencies)) { - unresolvedDependenciesAnalyzer.analyze(configuration.getResolvedConfiguration() - .getLenientConfiguration().getUnresolvedModuleDependencies()); - } - }); - }); - project.getGradle().buildFinished((buildResult) -> unresolvedDependenciesAnalyzer.buildFinished(project)); - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/UnresolvedDependenciesAnalyzer.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/UnresolvedDependenciesAnalyzer.java deleted file mode 100644 index 8da6fdbef5a..00000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/UnresolvedDependenciesAnalyzer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.gradle.plugin; - -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -import io.spring.gradle.dependencymanagement.DependencyManagementPlugin; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.gradle.api.Project; -import org.gradle.api.artifacts.ModuleVersionSelector; -import org.gradle.api.artifacts.UnresolvedDependency; - -/** - * An analyzer for {@link UnresolvedDependency unresolvable dependencies} that logs a - * warning suggesting that the {@code io.spring.dependency-management} plugin is applied - * when one or more versionless dependencies fails to resolve. - * - * @author Andy Wilkinson - */ -class UnresolvedDependenciesAnalyzer { - - private static final Log logger = LogFactory.getLog(SpringBootPlugin.class); - - private Set dependenciesWithNoVersion = new HashSet<>(); - - void analyze(Set unresolvedDependencies) { - this.dependenciesWithNoVersion = unresolvedDependencies.stream() - .map((unresolvedDependency) -> unresolvedDependency.getSelector()).filter(this::hasNoVersion) - .collect(Collectors.toSet()); - } - - void buildFinished(Project project) { - if (!this.dependenciesWithNoVersion.isEmpty() - && !project.getPlugins().hasPlugin(DependencyManagementPlugin.class)) { - StringBuilder message = new StringBuilder(); - message.append("\nDuring the build, one or more dependencies that were " - + "declared without a version failed to resolve:\n"); - this.dependenciesWithNoVersion - .forEach((dependency) -> message.append(" ").append(dependency).append("\n")); - message.append("\nDid you forget to apply the io.spring.dependency-management plugin to the "); - message.append(project.getName()).append(" project?\n"); - logger.warn(message.toString()); - } - } - - private boolean hasNoVersion(ModuleVersionSelector selector) { - String version = selector.getVersion(); - return version == null || version.trim().isEmpty(); - } - -} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java index ce7638f0bb3..210e98fee80 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginActionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,12 @@ package org.springframework.boot.gradle.plugin; -import java.io.File; -import java.io.IOException; - -import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.TaskOutcome; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.gradle.junit.GradleCompatibilityExtension; import org.springframework.boot.gradle.testkit.GradleBuild; -import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -53,19 +48,4 @@ class DependencyManagementPluginActionIntegrationTests { .task(":hasDependencyManagement").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); } - @TestTemplate - void helpfulErrorWhenVersionlessDependencyFailsToResolve() throws IOException { - File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example"); - examplePackage.mkdirs(); - FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), examplePackage); - BuildResult result = this.gradleBuild.buildAndFail("compileJava"); - assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.FAILED); - String output = result.getOutput(); - assertThat(output).contains("During the build, one or more dependencies that " - + "were declared without a version failed to resolve:"); - assertThat(output).contains("org.springframework.boot:spring-boot-starter-web:"); - assertThat(output).contains("Did you forget to apply the io.spring.dependency-management plugin to the " - + this.gradleBuild.getProjectDir().getName() + " project?"); - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootPluginIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootPluginIntegrationTests.java index cb9de0283ff..2184f2edad1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootPluginIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/SpringBootPluginIntegrationTests.java @@ -75,16 +75,6 @@ class SpringBootPluginIntegrationTests { this.gradleBuild.gradleVersion("6.3").build(); } - @Test - void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails() throws IOException { - createMinimalMainSource(); - BuildResult result = this.gradleBuild.buildAndFail("compileJava"); - assertThat(result.getOutput()) - .contains("During the build, one or more dependencies that were declared without a" - + " version failed to resolve:") - .contains(" org.springframework.boot:spring-boot-starter:"); - } - private void createMinimalMainSource() throws IOException { File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example"); examplePackage.mkdirs();