Merge branch '2.2.x'

Closes gh-21341
pull/21361/head
Andy Wilkinson 5 years ago
commit 70c4baeef6

@ -36,6 +36,8 @@ import org.gradle.api.plugins.ApplicationPluginConvention;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
import org.gradle.jvm.application.tasks.CreateStartScripts;
import org.gradle.util.GradleVersion;
import org.springframework.boot.gradle.tasks.application.CreateBootStartScripts;
@ -53,8 +55,8 @@ final class ApplicationPluginAction implements PluginApplicationAction {
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot");
configureBaseNameConvention(project, applicationConvention, distribution);
CreateBootStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
CreateBootStartScripts.class);
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
determineCreateStartScriptsClass());
bootStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
@ -79,6 +81,14 @@ final class ApplicationPluginAction implements PluginApplicationAction {
distribution.getContents().with(binCopySpec);
}
private Class<? extends CreateStartScripts> determineCreateStartScriptsClass() {
return isGradle64OrLater() ? CreateStartScripts.class : CreateBootStartScripts.class;
}
private boolean isGradle64OrLater() {
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.4")) >= 0;
}
@SuppressWarnings("unchecked")
private void configureBaseNameConvention(Project project, ApplicationPluginConvention applicationConvention,
Distribution distribution) {

@ -79,8 +79,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void zipDistributionForJarCanBeBuilt() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistZip")
.task(":bootDistZip").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
assertThat(distribution).isFile();
@ -91,8 +91,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void tarDistributionForJarCanBeBuilt() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistTar")
.task(":bootDistTar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();
@ -103,8 +103,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void zipDistributionForWarCanBeBuilt() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistZip")
.task(":bootDistZip").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
assertThat(distribution).isFile();
@ -115,8 +115,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void tarDistributionForWarCanBeBuilt() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistTar")
.task(":bootDistTar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();
@ -127,8 +127,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void applicationNameCanBeUsedToCustomizeDistributionName() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistTar")
.task(":bootDistTar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/custom-boot.tar");
assertThat(distribution).isFile();
String name = this.gradleBuild.getProjectDir().getName();
@ -139,8 +139,8 @@ class ApplicationPluginActionIntegrationTests {
@TestTemplate
void scriptsHaveCorrectPermissions() throws IOException {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.4").build("bootDistTar")
.task(":bootDistTar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();

@ -31,8 +31,8 @@ task('javaCompileEncoding') {
task('startScriptsDefaultJvmOpts') {
doFirst {
tasks.withType(org.springframework.boot.gradle.tasks.application.CreateBootStartScripts) {
println "${name} defaultJvmOpts = ${defaultJvmOpts}"
tasks.getByName("bootStartScripts") {
println "$name defaultJvmOpts = $defaultJvmOpts"
}
}
}

Loading…
Cancel
Save