Browse Source

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
pull/1588/head
Andy Wilkinson 11 years ago
parent
commit
06ffd9dd86
  1. 12
      spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java
  2. 15
      spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java
  3. 26
      spring-boot-integration-tests/src/test/resources/spring-loaded-old-gradle/build.gradle
  4. 25
      spring-boot-integration-tests/src/test/resources/spring-loaded-old-gradle/src/main/java/test/Application.java
  5. 10
      spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/RunPluginFeatures.java

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

@ -30,6 +30,16 @@ import org.springframework.util.FileSystemUtils; @@ -30,6 +30,16 @@ import org.springframework.util.FileSystemUtils;
*/
public class ProjectCreator {
private String gradleVersion;
public ProjectCreator() {
this("1.12");
}
public ProjectCreator(String gradleVersion) {
this.gradleVersion = gradleVersion;
}
public ProjectConnection createProject(String name) throws IOException {
File projectDirectory = new File("target/" + name);
projectDirectory.mkdirs();
@ -46,7 +56,7 @@ public class ProjectCreator { @@ -46,7 +56,7 @@ public class ProjectCreator {
}
GradleConnector gradleConnector = GradleConnector.newConnector();
gradleConnector.useGradleVersion("1.12");
gradleConnector.useGradleVersion(this.gradleVersion);
((DefaultGradleConnector) gradleConnector).embedded(true);
return gradleConnector.forProjectDirectory(projectDirectory).connect();

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

@ -60,6 +60,21 @@ public class SpringLoadedTests { @@ -60,6 +60,21 @@ public class SpringLoadedTests {
"-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
}
@Test
public void springLoadedCanBeUsedWithGradle16() throws IOException {
ProjectConnection project = new ProjectCreator("1.6")
.createProject("spring-loaded-old-gradle");
project.newBuild()
.forTasks("bootRun")
.withArguments("-PbootVersion=" + BOOT_VERSION,
"-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
.run();
List<String> output = getOutput();
assertOutputMatches(
"-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
}
private List<String> getOutput() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(new File(
"target/spring-loaded-jvm-args/build/output.txt")));

26
spring-boot-integration-tests/src/test/resources/spring-loaded-old-gradle/build.gradle

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}")
classpath("org.springframework:springloaded:${project.springLoadedVersion}")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter")
}
jar {
baseName = 'spring-loaded-old-gradle'
}

25
spring-boot-integration-tests/src/test/resources/spring-loaded-old-gradle/src/main/java/test/Application.java

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
package test;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
public class Application {
public static void main(String[] args) throws Exception {
PrintWriter writer = new PrintWriter(new FileWriter(new File("build/output.txt")));
for (String argument: ManagementFactory.getRuntimeMXBean().getInputArguments()) {
writer.println(argument);
}
writer.close();
}
}

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

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.boot.gradle.run;
import java.util.Collections;
import java.util.concurrent.Callable;
import org.gradle.api.Action;
@ -74,9 +75,14 @@ public class RunPluginFeatures implements PluginFeatures { @@ -74,9 +75,14 @@ public class RunPluginFeatures implements PluginFeatures {
run.getConventionMapping().map("jvmArgs", new Callable<Object>() {
@Override
public Object call() throws Exception {
return project.property("applicationDefaultJvmArgs");
if (project.hasProperty("applicationDefaultJvmArgs")) {
return project.property("applicationDefaultJvmArgs");
}
else {
return Collections.emptyList();
}
}
});
}
}

Loading…
Cancel
Save