Fix reflective access to archiveBaseName property

Previously, reflective access to the archiveBaseName property
incorrectly treated the property as a String. It should have been
treated as a Property<String>. This caused an exception to be thrown
and the deprecated baseName property to be used as a fallback.

This commit corrects the reflective access to the archiveBaseName
property. It also updates the tests to fail if a build outputs a
deprecation warning. Tests that use Gradle's Maven plugin have been
updated to expect deprecation warnings when run with Gradle 6.0 where
the plugin is deprecated. Tests that configure an archive's base name
have been updated to use archiveBaseName when running with Gradle 6.0
and later.

Closes gh-18663
This commit is contained in:
Andy Wilkinson
2019-11-27 12:45:23 +00:00
parent a58ae98f9d
commit 76f03a8cad
8 changed files with 54 additions and 18 deletions

View File

@@ -22,12 +22,12 @@ import java.io.IOException;
import java.util.Properties;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.Test;
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.tasks.buildinfo.BuildInfo;
import org.springframework.boot.gradle.testkit.GradleBuild;
import org.springframework.boot.gradle.testkit.GradleBuildExtension;
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@ExtendWith(GradleBuildExtension.class)
@ExtendWith(GradleCompatibilityExtension.class)
class BuildInfoDslIntegrationTests {
final GradleBuild gradleBuild = new GradleBuild();
GradleBuild gradleBuild;
@Test
@TestTemplate
void basicJar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -53,7 +53,7 @@ class BuildInfoDslIntegrationTests {
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
@TestTemplate
void jarWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -64,7 +64,7 @@ class BuildInfoDslIntegrationTests {
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
@TestTemplate
void basicWar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -75,7 +75,7 @@ class BuildInfoDslIntegrationTests {
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
@TestTemplate
void warWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -86,7 +86,7 @@ class BuildInfoDslIntegrationTests {
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
@TestTemplate
void additionalProperties() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -99,7 +99,7 @@ class BuildInfoDslIntegrationTests {
assertThat(properties).containsEntry("build.b", "bravo");
}
@Test
@TestTemplate
void classesDependency() throws IOException {
assertThat(this.gradleBuild.build("classes", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);

View File

@@ -36,7 +36,8 @@ public class MavenPluginActionIntegrationTests {
@TestTemplate
public void clearsConf2ScopeMappingsOfUploadBootArchivesTask() {
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput()).contains("Conf2ScopeMappings = 0");
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.0.0").build("conf2ScopeMappings")
.getOutput()).contains("Conf2ScopeMappings = 0");
}
}

View File

@@ -42,7 +42,8 @@ public class MavenIntegrationTests {
@TestTemplate
public void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
BuildResult result = this.gradleBuild.build("uploadBootArchives");
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.0.0")
.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("jar")).isFile();
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
@@ -51,7 +52,8 @@ public class MavenIntegrationTests {
@TestTemplate
public void bootWarCanBeUploaded() throws IOException {
BuildResult result = this.gradleBuild.build("uploadBootArchives");
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.0.0")
.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("war")).isFile();
assertThat(artifactWithSuffix("pom"))

View File

@@ -32,6 +32,7 @@ import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.util.GradleVersion;
import org.jetbrains.kotlin.cli.common.PropertiesKt;
import org.jetbrains.kotlin.compilerRunner.KotlinLogger;
import org.jetbrains.kotlin.daemon.client.KotlinCompilerClient;
@@ -44,6 +45,8 @@ import org.springframework.boot.loader.tools.LaunchScript;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A {@code GradleBuild} is used to run a Gradle build using {@link GradleRunner}.
*
@@ -59,6 +62,8 @@ public class GradleBuild {
private String gradleVersion;
private GradleVersion expectDeprecationWarnings;
public GradleBuild() {
this(Dsl.GROOVY);
}
@@ -100,9 +105,19 @@ public class GradleBuild {
return this;
}
public GradleBuild expectDeprecationWarningsWithAtLeastVersion(String gradleVersion) {
this.expectDeprecationWarnings = GradleVersion.version(gradleVersion);
return this;
}
public BuildResult build(String... arguments) {
try {
return prepareRunner(arguments).build();
BuildResult result = prepareRunner(arguments).build();
if (this.gradleVersion != null && this.expectDeprecationWarnings != null
&& this.expectDeprecationWarnings.compareTo(GradleVersion.version(this.gradleVersion)) > 0) {
assertThat(result.getOutput()).doesNotContain("Deprecated").doesNotContain("deprecated");
}
return result;
}
catch (Exception ex) {
throw new RuntimeException(ex);