Guide users to apply dependency management plugin when resolution fails
This commit is contained in:
@@ -16,11 +16,16 @@
|
||||
|
||||
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.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -50,4 +55,23 @@ public class DependencyManagementPluginActionIntegrationTests {
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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?");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,22 +126,35 @@ public class GradleBuild implements TestRule {
|
||||
|
||||
public BuildResult build(String... arguments) {
|
||||
try {
|
||||
Files.copy(new File(this.script).toPath(),
|
||||
new File(this.projectDir, "build.gradle").toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
GradleRunner gradleRunner = GradleRunner.create()
|
||||
.withProjectDir(this.projectDir).forwardOutput();
|
||||
List<String> allArguments = new ArrayList<String>();
|
||||
allArguments.add("-PpluginClasspath=" + pluginClasspath());
|
||||
allArguments.add("-PbootVersion=" + getBootVersion());
|
||||
allArguments.addAll(Arrays.asList(arguments));
|
||||
return gradleRunner.withArguments(allArguments).build();
|
||||
return prepareRunner(arguments).build();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public BuildResult buildAndFail(String... arguments) {
|
||||
try {
|
||||
return prepareRunner(arguments).buildAndFail();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public GradleRunner prepareRunner(String... arguments) throws IOException {
|
||||
Files.copy(new File(this.script).toPath(),
|
||||
new File(this.projectDir, "build.gradle").toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir)
|
||||
.forwardOutput();
|
||||
List<String> allArguments = new ArrayList<String>();
|
||||
allArguments.add("-PpluginClasspath=" + pluginClasspath());
|
||||
allArguments.add("-PbootVersion=" + getBootVersion());
|
||||
allArguments.addAll(Arrays.asList(arguments));
|
||||
return gradleRunner.withArguments(allArguments);
|
||||
}
|
||||
|
||||
public File getProjectDir() {
|
||||
return this.projectDir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user