Skip to content

Commit c84b35c

Browse files
committed
Polish "Avoid using Gradle APIs that trigger eager task creation"
See spring-projectsgh-29762
1 parent 7cd87ac commit c84b35c

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java

+26-22
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,37 @@ public void execute(Project project) {
5151
distribution.getDistributionBaseName()
5252
.convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
5353
TaskProvider<CreateStartScripts> bootStartScripts = project.getTasks().register("bootStartScripts",
54-
CreateStartScripts.class, (bss) -> {
55-
bss.setDescription(
56-
"Generates OS-specific start scripts to run the project as a Spring Boot application.");
57-
((TemplateBasedScriptGenerator) bss.getUnixStartScriptGenerator()).setTemplate(
58-
project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
59-
((TemplateBasedScriptGenerator) bss.getWindowsStartScriptGenerator()).setTemplate(
60-
project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
61-
62-
project.getConfigurations().all((configuration) -> {
63-
if ("bootArchives".equals(configuration.getName())) {
64-
CopySpec libCopySpec = project.copySpec().into("lib")
65-
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
66-
libCopySpec.setFileMode(0644);
67-
distribution.getContents().with(libCopySpec);
68-
bss.setClasspath(configuration.getArtifacts().getFiles());
69-
}
70-
});
71-
bss.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
72-
bss.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
73-
bss.getConventionMapping().map("defaultJvmOpts",
74-
applicationConvention::getApplicationDefaultJvmArgs);
75-
});
54+
CreateStartScripts.class,
55+
(task) -> configureCreateStartScripts(project, applicationConvention, distribution, task));
7656
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
7757
binCopySpec.setFileMode(0755);
7858
distribution.getContents().with(binCopySpec);
7959
}
8060

61+
private void configureCreateStartScripts(Project project, ApplicationPluginConvention applicationConvention,
62+
Distribution distribution, CreateStartScripts createStartScripts) {
63+
createStartScripts
64+
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
65+
((TemplateBasedScriptGenerator) createStartScripts.getUnixStartScriptGenerator())
66+
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
67+
((TemplateBasedScriptGenerator) createStartScripts.getWindowsStartScriptGenerator())
68+
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
69+
project.getConfigurations().all((configuration) -> {
70+
if ("bootArchives".equals(configuration.getName())) {
71+
CopySpec libCopySpec = project.copySpec().into("lib")
72+
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
73+
libCopySpec.setFileMode(0644);
74+
distribution.getContents().with(libCopySpec);
75+
createStartScripts.setClasspath(configuration.getArtifacts().getFiles());
76+
}
77+
});
78+
createStartScripts.getConventionMapping().map("outputDir",
79+
() -> new File(project.getBuildDir(), "bootScripts"));
80+
createStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
81+
createStartScripts.getConventionMapping().map("defaultJvmOpts",
82+
applicationConvention::getApplicationDefaultJvmArgs);
83+
}
84+
8185
@Override
8286
public Class<? extends Plugin<Project>> getPluginClass() {
8387
return ApplicationPlugin.class;

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/KotlinPluginAction.java

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

0 commit comments

Comments
 (0)