Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;

Expand All @@ -49,26 +50,29 @@ public void execute(Project project) {
Distribution distribution = distributions.create("boot");
distribution.getDistributionBaseName()
.convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts.class);
bootStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
((TemplateBasedScriptGenerator) bootStartScripts.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);
bootStartScripts.setClasspath(configuration.getArtifacts().getFiles());
}
});
bootStartScripts.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
bootStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
bootStartScripts.getConventionMapping().map("defaultJvmOpts",
applicationConvention::getApplicationDefaultJvmArgs);
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")));

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());
}
});
bss.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
bss.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
bss.getConventionMapping().map("defaultJvmOpts",
applicationConvention::getApplicationDefaultJvmArgs);
});
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0755);
distribution.getContents().with(binCopySpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@ private JavaPluginConvention javaPluginConvention(Project project) {
}

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);
Expand All @@ -184,8 +185,8 @@ private void configureParametersCompilerArg(Project project) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private String getKotlinVersion(Project project) {
}

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
Expand Down