Skip to content

Commit 1e0c129

Browse files
committed
Enable predictive test selection for local builds
Closes gh-35869
1 parent 984dc1d commit 1e0c129

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.stream.Collectors;
2626

2727
import com.gradle.enterprise.gradleplugin.testretry.TestRetryExtension;
28+
import com.gradle.enterprise.gradleplugin.testselection.PredictiveTestSelectionExtension;
2829
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
2930
import io.spring.javaformat.gradle.tasks.CheckFormat;
3031
import io.spring.javaformat.gradle.tasks.Format;
@@ -68,6 +69,8 @@
6869
* <li>to use JUnit Platform
6970
* <li>with a max heap of 1024M
7071
* <li>to run after any Checkstyle and format checking tasks
72+
* <li>to enable retries with a maximum of three attempts when running on CI
73+
* <li>to use predictive test selection when running locally
7174
* </ul>
7275
* <li>A {@code testRuntimeOnly} dependency upon
7376
* {@code org.junit.platform:junit-platform-launcher} is added to projects with the
@@ -164,15 +167,28 @@ private void configureTestConventions(Project project) {
164167
test.setMaxHeapSize("1024M");
165168
project.getTasks().withType(Checkstyle.class, test::mustRunAfter);
166169
project.getTasks().withType(CheckFormat.class, test::mustRunAfter);
167-
TestRetryExtension testRetry = test.getExtensions().getByType(TestRetryExtension.class);
168-
testRetry.getFailOnPassedAfterRetry().set(true);
169-
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
170+
configureTestRetries(test);
171+
configurePredictiveTestSelection(test);
170172
});
171173
project.getPlugins()
172174
.withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
173175
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
174176
}
175177

178+
private void configureTestRetries(Test test) {
179+
TestRetryExtension testRetry = test.getExtensions().getByType(TestRetryExtension.class);
180+
testRetry.getFailOnPassedAfterRetry().set(true);
181+
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
182+
}
183+
184+
private void configurePredictiveTestSelection(Test test) {
185+
if (!isCi()) {
186+
PredictiveTestSelectionExtension predictiveTestSelection = test.getExtensions()
187+
.getByType(PredictiveTestSelectionExtension.class);
188+
predictiveTestSelection.getEnabled().set(true);
189+
}
190+
}
191+
176192
private boolean isCi() {
177193
return Boolean.parseBoolean(System.getenv("CI"));
178194
}

0 commit comments

Comments
 (0)