Merge pull request #29762 from larsgrefer
* gh-29762: Polish "Avoid using Gradle APIs that trigger eager task creation" Avoid using Gradle APIs that trigger eager task creation Closes gh-29762
This commit is contained in:
commit
7f196d33fb
|
@ -31,6 +31,7 @@ import org.gradle.api.file.CopySpec;
|
|||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.plugins.ApplicationPlugin;
|
||||
import org.gradle.api.plugins.ApplicationPluginConvention;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
|
||||
import org.gradle.jvm.application.tasks.CreateStartScripts;
|
||||
|
||||
|
@ -49,12 +50,21 @@ final class ApplicationPluginAction implements PluginApplicationAction {
|
|||
Distribution distribution = distributions.create("boot");
|
||||
distribution.getDistributionBaseName()
|
||||
.convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
|
||||
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts.class);
|
||||
bootStartScripts
|
||||
TaskProvider<CreateStartScripts> bootStartScripts = project.getTasks().register("bootStartScripts",
|
||||
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) bootStartScripts.getUnixStartScriptGenerator())
|
||||
((TemplateBasedScriptGenerator) createStartScripts.getUnixStartScriptGenerator())
|
||||
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
|
||||
((TemplateBasedScriptGenerator) bootStartScripts.getWindowsStartScriptGenerator())
|
||||
((TemplateBasedScriptGenerator) createStartScripts.getWindowsStartScriptGenerator())
|
||||
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
|
||||
project.getConfigurations().all((configuration) -> {
|
||||
if ("bootArchives".equals(configuration.getName())) {
|
||||
|
@ -62,16 +72,14 @@ final class ApplicationPluginAction implements PluginApplicationAction {
|
|||
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
|
||||
libCopySpec.setFileMode(0644);
|
||||
distribution.getContents().with(libCopySpec);
|
||||
bootStartScripts.setClasspath(configuration.getArtifacts().getFiles());
|
||||
createStartScripts.setClasspath(configuration.getArtifacts().getFiles());
|
||||
}
|
||||
});
|
||||
bootStartScripts.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
|
||||
bootStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
|
||||
bootStartScripts.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
|
||||
|
|
|
@ -167,15 +167,16 @@ final class JavaPluginAction implements PluginApplicationAction {
|
|||
}
|
||||
|
||||
private void configureUtf8Encoding(Project project) {
|
||||
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class, (compile) -> {
|
||||
if (compile.getOptions().getEncoding() == null) {
|
||||
compile.getOptions().setEncoding("UTF-8");
|
||||
}
|
||||
}));
|
||||
project.afterEvaluate(
|
||||
(evaluated) -> evaluated.getTasks().withType(JavaCompile.class).configureEach((compile) -> {
|
||||
if (compile.getOptions().getEncoding() == null) {
|
||||
compile.getOptions().setEncoding("UTF-8");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void configureParametersCompilerArg(Project project) {
|
||||
project.getTasks().withType(JavaCompile.class, (compile) -> {
|
||||
project.getTasks().withType(JavaCompile.class).configureEach((compile) -> {
|
||||
List<String> compilerArgs = compile.getOptions().getCompilerArgs();
|
||||
if (!compilerArgs.contains(PARAMETERS_COMPILER_ARG)) {
|
||||
compilerArgs.add(PARAMETERS_COMPILER_ARG);
|
||||
|
@ -184,8 +185,8 @@ final class JavaPluginAction implements PluginApplicationAction {
|
|||
}
|
||||
|
||||
private void configureAdditionalMetadataLocations(Project project) {
|
||||
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class,
|
||||
this::configureAdditionalMetadataLocations));
|
||||
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class)
|
||||
.configureEach(this::configureAdditionalMetadataLocations));
|
||||
}
|
||||
|
||||
private void configureAdditionalMetadataLocations(JavaCompile compile) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -47,8 +47,8 @@ class KotlinPluginAction implements PluginApplicationAction {
|
|||
}
|
||||
|
||||
private void enableJavaParametersOption(Project project) {
|
||||
project.getTasks().withType(KotlinCompile.class,
|
||||
(compile) -> compile.getKotlinOptions().setJavaParameters(true));
|
||||
project.getTasks().withType(KotlinCompile.class)
|
||||
.configureEach((compile) -> compile.getKotlinOptions().setJavaParameters(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue