diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 2772207c450..33a07fcea0d 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -20,6 +20,7 @@ dependencies {
implementation("org.apache.maven:maven-embedder:3.6.2")
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.0.0")
implementation("org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.0.0")
+ implementation("org.gradle:test-retry-gradle-plugin:1.1.3")
implementation("org.springframework:spring-core:5.2.2.RELEASE")
implementation("org.springframework:spring-web:5.2.2.RELEASE")
implementation("com.google.code.gson:gson:2.8.5")
diff --git a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java
index 1941228ed48..52c3b03de1c 100644
--- a/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java
+++ b/buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java
@@ -56,6 +56,8 @@ import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
+import org.gradle.testretry.TestRetryPlugin;
+import org.gradle.testretry.TestRetryTaskExtension;
import org.springframework.boot.build.testing.TestFailuresPlugin;
import org.springframework.util.FileCopyUtils;
@@ -71,7 +73,8 @@ import org.springframework.util.FileCopyUtils;
*
* - {@code sourceCompatibility} is set to {@code 1.8}
*
- {@link SpringJavaFormatPlugin Spring Java Format}, {@link CheckstylePlugin
- * Checkstyle}, and {@link TestFailuresPlugin Test Failures} plugins are applied
+ * Checkstyle}, {@link TestFailuresPlugin Test Failures}, and {@link TestRetryPlugin Test
+ * Retry} plugins are applied
*
- {@link Test} tasks are configured to use JUnit Platform and use a max heap of 1024M
*
- {@link JavaCompile}, {@link Javadoc}, and {@link FormatTask} tasks are configured
* to use UTF-8 encoding
@@ -139,10 +142,16 @@ public class ConventionsPlugin implements Plugin {
javadoc.getOptions().source("1.8").encoding("UTF-8");
withOptionalBuildJavaHome(project, (javaHome) -> javadoc.setExecutable(javaHome + "/bin/javadoc"));
});
+ 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);
+ });
});
project.getTasks().withType(Jar.class, (jar) -> {
project.afterEvaluate((evaluated) -> {
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 1a3d2aab5d6..fffd9a46602 100644
--- a/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java
+++ b/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java
@@ -24,6 +24,7 @@ import java.io.PrintWriter;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -74,8 +75,29 @@ class ConventionsPluginTests {
}
}
- private void runGradle(String... args) {
- GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build();
+ @Test
+ void testRetryIsConfigured() 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(" test.retry {");
+ out.println(" println \"maxRetries: ${maxRetries.get()}\"");
+ out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\"");
+ out.println(" }");
+ out.println(" }");
+ out.println("}");
+ }
+ assertThat(runGradle("retryConfig", "--stacktrace").getOutput()).contains("maxRetries: 3")
+ .contains("failOnPassedAfterRetry: true");
+ }
+
+ private BuildResult runGradle(String... args) {
+ return GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build();
}
}