Polish "Avoid using Gradle APIs that trigger eager task creation"

See gh-29762
pull/29827/head
Andy Wilkinson 3 years ago
parent 7cd87acd73
commit c84b35c460

@ -51,31 +51,35 @@ final class ApplicationPluginAction implements PluginApplicationAction {
distribution.getDistributionBaseName()
.convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
TaskProvider<CreateStartScripts> bootStartScripts = project.getTasks().register("bootStartScripts",
CreateStartScripts.class, (bss) -> {
bss.setDescription(
"Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bss.getUnixStartScriptGenerator()).setTemplate(
project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
((TemplateBasedScriptGenerator) bss.getWindowsStartScriptGenerator()).setTemplate(
project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
CreateStartScripts.class,
(task) -> configureCreateStartScripts(project, applicationConvention, distribution, task));
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0755);
distribution.getContents().with(binCopySpec);
}
private void configureCreateStartScripts(Project project, ApplicationPluginConvention applicationConvention,
Distribution distribution, CreateStartScripts createStartScripts) {
createStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) createStartScripts.getUnixStartScriptGenerator())
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
((TemplateBasedScriptGenerator) createStartScripts.getWindowsStartScriptGenerator())
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
project.getConfigurations().all((configuration) -> {
if ("bootArchives".equals(configuration.getName())) {
CopySpec libCopySpec = project.copySpec().into("lib")
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
libCopySpec.setFileMode(0644);
distribution.getContents().with(libCopySpec);
bss.setClasspath(configuration.getArtifacts().getFiles());
createStartScripts.setClasspath(configuration.getArtifacts().getFiles());
}
});
bss.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
bss.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
bss.getConventionMapping().map("defaultJvmOpts",
createStartScripts.getConventionMapping().map("outputDir",
() -> new File(project.getBuildDir(), "bootScripts"));
createStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
createStartScripts.getConventionMapping().map("defaultJvmOpts",
applicationConvention::getApplicationDefaultJvmArgs);
});
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0755);
distribution.getContents().with(binCopySpec);
}
@Override

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

Loading…
Cancel
Save