diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index c92a20ba45..883a8f10a1 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -107,17 +107,19 @@ class JavaConventions { } private void configureTestConventions(Project project) { - project.getPlugins().apply(TestRetryPlugin.class); - project.getTasks().withType(Test.class, (test) -> { - withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java")); - test.useJUnitPlatform(); - test.setMaxHeapSize("1024M"); - project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> { - TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class); - testRetry.getFailOnPassedAfterRetry().set(true); - testRetry.getMaxRetries().set(3); + if (Boolean.valueOf(System.getenv("CI"))) { + project.getPlugins().apply(TestRetryPlugin.class); + project.getTasks().withType(Test.class, (test) -> { + withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java")); + test.useJUnitPlatform(); + test.setMaxHeapSize("1024M"); + project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> { + TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class); + testRetry.getFailOnPassedAfterRetry().set(true); + testRetry.getMaxRetries().set(3); + }); }); - }); + } } private void configureJavadocConventions(Project project) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java b/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java index fffd9a4660..48bcf84293 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java @@ -21,6 +21,8 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.util.Collections; +import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -76,7 +78,7 @@ class ConventionsPluginTests { } @Test - void testRetryIsConfigured() throws IOException { + void testRetryIsConfiguredOnCI() throws IOException { try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) { out.println("plugins {"); out.println(" id 'java'"); @@ -85,6 +87,7 @@ class ConventionsPluginTests { out.println("description 'Test'"); out.println("task retryConfig {"); out.println(" doLast {"); + out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\""); out.println(" test.retry {"); out.println(" println \"maxRetries: ${maxRetries.get()}\""); out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\""); @@ -92,12 +95,36 @@ class ConventionsPluginTests { out.println(" }"); out.println("}"); } - assertThat(runGradle("retryConfig", "--stacktrace").getOutput()).contains("maxRetries: 3") + assertThat(runGradle(Collections.singletonMap("CI", "true"), "retryConfig", "--stacktrace").getOutput()) + .contains("Retry plugin applied: true").contains("maxRetries: 3") .contains("failOnPassedAfterRetry: true"); } + @Test + void testRetryIsNotConfiguredLocally() throws IOException { + try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) { + out.println("plugins {"); + out.println(" id 'java'"); + out.println(" id 'org.springframework.boot.conventions'"); + out.println("}"); + out.println("description 'Test'"); + out.println("task retryConfig {"); + out.println(" doLast {"); + out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\""); + out.println(" }"); + out.println("}"); + } + assertThat(runGradle(Collections.singletonMap("CI", "local"), "retryConfig", "--stacktrace").getOutput()) + .contains("Retry plugin applied: false"); + } + private BuildResult runGradle(String... args) { - return GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build(); + return runGradle(Collections.emptyMap(), args); + } + + private BuildResult runGradle(Map environment, String... args) { + return GradleRunner.create().withProjectDir(this.projectDir).withEnvironment(environment).withArguments(args) + .withPluginClasspath().build(); } }