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.Property;
import org.gradle.api.provider.Provider; import org.gradle.api.provider.Provider;
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator; 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; import org.springframework.boot.gradle.tasks.application.CreateBootStartScripts;
@ -53,8 +55,8 @@ final class ApplicationPluginAction implements PluginApplicationAction {
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class); DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot"); Distribution distribution = distributions.create("boot");
configureBaseNameConvention(project, applicationConvention, distribution); configureBaseNameConvention(project, applicationConvention, distribution);
CreateBootStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
CreateBootStartScripts.class); determineCreateStartScriptsClass());
bootStartScripts bootStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application."); .setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator()) ((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
@ -79,6 +81,14 @@ final class ApplicationPluginAction implements PluginApplicationAction {
distribution.getContents().with(binCopySpec); 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") @SuppressWarnings("unchecked")
private void configureBaseNameConvention(Project project, ApplicationPluginConvention applicationConvention, private void configureBaseNameConvention(Project project, ApplicationPluginConvention applicationConvention,
Distribution distribution) { Distribution distribution) {

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

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

Loading…
Cancel
Save