Skip to content

Commit 00449be

Browse files
committed
Use app…DefaultJvmArgs as convention for start script's defaultJvmOpts
Closes gh-12631
1 parent 624946a commit 00449be

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/reacting.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ applied to a project, the Spring Boot plugin will automatically import the
7070
When Gradle's {application-plugin}[`application` plugin] is applied to a project, the
7171
Spring Boot plugin:
7272

73-
1. Creates a `CreateStartScripts` task named `bootStartScripts` that will creates scripts
74-
that launch the artifact in the `bootArchives` configuration using `java -jar`.
73+
1. Creates a `CreateStartScripts` task named `bootStartScripts` that will create scripts
74+
that launch the artifact in the `bootArchives` configuration using `java -jar`. The
75+
task is configured to use the `applicationDefaultJvmArgs` property as a convention
76+
for its `defaultJvmOpts` property.
7577
2. Creates a new distribution named `boot` and configures it to contain the artifact in
7678
the `bootArchives` configuration in its `lib` directory and the start scripts in its
7779
`bin` directory.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public void execute(Project project) {
7777
() -> new File(project.getBuildDir(), "bootScripts"));
7878
bootStartScripts.getConventionMapping().map("applicationName",
7979
applicationConvention::getApplicationName);
80+
bootStartScripts.getConventionMapping().map("defaultJvmOpts",
81+
applicationConvention::getApplicationDefaultJvmArgs);
8082
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
8183
binCopySpec.setFileMode(0x755);
8284
distribution.getContents().with(binCopySpec);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/ApplicationPluginActionIntegrationTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public void applyingApplicationPluginCreatesBootStartScriptsTask() {
7373
.contains("bootStartScripts exists = true");
7474
}
7575

76+
@Test
77+
public void createsBootStartScriptsTaskUsesApplicationPluginsDefaultJvmOpts() {
78+
assertThat(this.gradleBuild
79+
.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin")
80+
.getOutput()).contains(
81+
"bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
82+
}
83+
7684
@Test
7785
public void zipDistributionForJarCanBeBuilt() throws IOException {
7886
assertThat(

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/ApplicationPluginActionIntegrationTests.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ apply plugin: 'org.springframework.boot'
88

99
if (project.hasProperty('applyApplicationPlugin')) {
1010
apply plugin: 'application'
11+
applicationDefaultJvmArgs = ['-Dcom.example.a=alpha', '-Dcom.example.b=bravo']
1112
}
1213

1314
task('taskExists') {
@@ -31,3 +32,11 @@ task('javaCompileEncoding') {
3132
}
3233
}
3334
}
35+
36+
task('startScriptsDefaultJvmOpts') {
37+
doFirst {
38+
tasks.withType(org.springframework.boot.gradle.tasks.application.CreateBootStartScripts) {
39+
println "$name defaultJvmOpts = $defaultJvmOpts"
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)