Use Gradle's CreateStartScripts task with 6.4 and later

Fixes gh-20759
pull/21480/head
Andy Wilkinson 5 years ago
parent addaf5ff18
commit 386d678d99

@ -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) {

@ -39,7 +39,7 @@ import org.springframework.boot.gradle.testkit.GradleBuildExtension;
public final class GradleCompatibilityExtension implements TestTemplateInvocationContextProvider {
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "5.0", "5.1.1", "5.2.1", "5.3.1",
"5.4.1", "5.5.1", "5.6.4", "6.0.1", "6.1.1", "6.2.2", "6.3");
"5.4.1", "5.5.1", "5.6.4", "6.0.1", "6.1.1", "6.2.2", "6.3", "6.4");
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {

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

Loading…
Cancel
Save