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 43ff4e8826..4444af68fd 100644
--- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java
+++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java
@@ -25,6 +25,7 @@ import java.util.TreeMap;
import java.util.stream.Collectors;
import com.gradle.enterprise.gradleplugin.testretry.TestRetryExtension;
+import com.gradle.enterprise.gradleplugin.testselection.PredictiveTestSelectionExtension;
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
import io.spring.javaformat.gradle.tasks.CheckFormat;
import io.spring.javaformat.gradle.tasks.Format;
@@ -69,6 +70,8 @@ import org.springframework.util.StringUtils;
*
to use JUnit Platform
* with a max heap of 1024M
* to run after any Checkstyle and format checking tasks
+ * to enable retries with a maximum of three attempts when running on CI
+ * to use predictive test selection when running locally
*
* A {@code testRuntimeOnly} dependency upon
* {@code org.junit.platform:junit-platform-launcher} is added to projects with the
@@ -165,15 +168,28 @@ class JavaConventions {
test.setMaxHeapSize("1024M");
project.getTasks().withType(Checkstyle.class, test::mustRunAfter);
project.getTasks().withType(CheckFormat.class, test::mustRunAfter);
- TestRetryExtension testRetry = test.getExtensions().getByType(TestRetryExtension.class);
- testRetry.getFailOnPassedAfterRetry().set(true);
- testRetry.getMaxRetries().set(isCi() ? 3 : 0);
+ configureTestRetries(test);
+ configurePredictiveTestSelection(test);
});
project.getPlugins()
.withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
}
+ private void configureTestRetries(Test test) {
+ TestRetryExtension testRetry = test.getExtensions().getByType(TestRetryExtension.class);
+ testRetry.getFailOnPassedAfterRetry().set(true);
+ testRetry.getMaxRetries().set(isCi() ? 3 : 0);
+ }
+
+ private void configurePredictiveTestSelection(Test test) {
+ if (!isCi()) {
+ PredictiveTestSelectionExtension predictiveTestSelection = test.getExtensions()
+ .getByType(PredictiveTestSelectionExtension.class);
+ predictiveTestSelection.getEnabled().set(true);
+ }
+ }
+
private boolean isCi() {
return Boolean.parseBoolean(System.getenv("CI"));
}