Skip to content

Commit 06ffd9d

Browse files
committed
Fix configuration of Spring Loaded on Gradle 1.6
The applicationDefaultJvmArgs property was added in Gradle 1.7. This commit updates RunPluginFeatures to access the property defensively so that the plugin can be used with Gradle 1.6. Fixes gh-1511
1 parent 750c116 commit 06ffd9d

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
*/
3131
public class ProjectCreator {
3232

33+
private String gradleVersion;
34+
35+
public ProjectCreator() {
36+
this("1.12");
37+
}
38+
39+
public ProjectCreator(String gradleVersion) {
40+
this.gradleVersion = gradleVersion;
41+
}
42+
3343
public ProjectConnection createProject(String name) throws IOException {
3444
File projectDirectory = new File("target/" + name);
3545
projectDirectory.mkdirs();
@@ -46,7 +56,7 @@ public ProjectConnection createProject(String name) throws IOException {
4656
}
4757

4858
GradleConnector gradleConnector = GradleConnector.newConnector();
49-
gradleConnector.useGradleVersion("1.12");
59+
gradleConnector.useGradleVersion(this.gradleVersion);
5060

5161
((DefaultGradleConnector) gradleConnector).embedded(true);
5262
return gradleConnector.forProjectDirectory(projectDirectory).connect();

spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured()
6060
"-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
6161
}
6262

63+
@Test
64+
public void springLoadedCanBeUsedWithGradle16() throws IOException {
65+
ProjectConnection project = new ProjectCreator("1.6")
66+
.createProject("spring-loaded-old-gradle");
67+
project.newBuild()
68+
.forTasks("bootRun")
69+
.withArguments("-PbootVersion=" + BOOT_VERSION,
70+
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
71+
.run();
72+
73+
List<String> output = getOutput();
74+
assertOutputMatches(
75+
"-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
76+
}
77+
6378
private List<String> getOutput() throws IOException {
6479
BufferedReader reader = new BufferedReader(new FileReader(new File(
6580
"target/spring-loaded-jvm-args/build/output.txt")));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
}
6+
dependencies {
7+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
8+
classpath("org.springframework:springloaded:${project.springLoadedVersion}")
9+
}
10+
}
11+
12+
apply plugin: 'java'
13+
apply plugin: 'spring-boot'
14+
15+
repositories {
16+
mavenLocal()
17+
mavenCentral()
18+
}
19+
20+
dependencies {
21+
compile("org.springframework.boot:spring-boot-starter")
22+
}
23+
24+
jar {
25+
baseName = 'spring-loaded-old-gradle'
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test;
2+
3+
import java.io.File;
4+
import java.io.FileWriter;
5+
import java.io.PrintWriter;
6+
import java.lang.management.ManagementFactory;
7+
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.ComponentScan;
13+
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.util.Assert;
15+
16+
public class Application {
17+
18+
public static void main(String[] args) throws Exception {
19+
PrintWriter writer = new PrintWriter(new FileWriter(new File("build/output.txt")));
20+
for (String argument: ManagementFactory.getRuntimeMXBean().getInputArguments()) {
21+
writer.println(argument);
22+
}
23+
writer.close();
24+
}
25+
}

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/RunPluginFeatures.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.gradle.run;
1818

19+
import java.util.Collections;
1920
import java.util.concurrent.Callable;
2021

2122
import org.gradle.api.Action;
@@ -74,9 +75,14 @@ public Object call() throws Exception {
7475
run.getConventionMapping().map("jvmArgs", new Callable<Object>() {
7576
@Override
7677
public Object call() throws Exception {
77-
return project.property("applicationDefaultJvmArgs");
78+
if (project.hasProperty("applicationDefaultJvmArgs")) {
79+
return project.property("applicationDefaultJvmArgs");
80+
}
81+
else {
82+
return Collections.emptyList();
83+
}
84+
7885
}
7986
});
8087
}
81-
8288
}

0 commit comments

Comments
 (0)