|
25 | 25 | import java.util.stream.Collectors;
|
26 | 26 |
|
27 | 27 | import com.gradle.enterprise.gradleplugin.testretry.TestRetryExtension;
|
| 28 | +import com.gradle.enterprise.gradleplugin.testselection.PredictiveTestSelectionExtension; |
28 | 29 | import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
|
29 | 30 | import io.spring.javaformat.gradle.tasks.CheckFormat;
|
30 | 31 | import io.spring.javaformat.gradle.tasks.Format;
|
|
68 | 69 | * <li>to use JUnit Platform
|
69 | 70 | * <li>with a max heap of 1024M
|
70 | 71 | * <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 |
71 | 74 | * </ul>
|
72 | 75 | * <li>A {@code testRuntimeOnly} dependency upon
|
73 | 76 | * {@code org.junit.platform:junit-platform-launcher} is added to projects with the
|
@@ -164,15 +167,28 @@ private void configureTestConventions(Project project) {
|
164 | 167 | test.setMaxHeapSize("1024M");
|
165 | 168 | project.getTasks().withType(Checkstyle.class, test::mustRunAfter);
|
166 | 169 | 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); |
170 | 172 | });
|
171 | 173 | project.getPlugins()
|
172 | 174 | .withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
|
173 | 175 | .add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
|
174 | 176 | }
|
175 | 177 |
|
| 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 | + |
176 | 192 | private boolean isCi() {
|
177 | 193 | return Boolean.parseBoolean(System.getenv("CI"));
|
178 | 194 | }
|
|
0 commit comments