mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Enable predictive test selection for local builds
Closes gh-35869
This commit is contained in:
parent
984dc1d58f
commit
1e0c129452
@ -25,6 +25,7 @@ import java.util.TreeMap;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.gradle.enterprise.gradleplugin.testretry.TestRetryExtension;
|
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.SpringJavaFormatPlugin;
|
||||||
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
import io.spring.javaformat.gradle.tasks.CheckFormat;
|
||||||
import io.spring.javaformat.gradle.tasks.Format;
|
import io.spring.javaformat.gradle.tasks.Format;
|
||||||
@ -68,6 +69,8 @@ import org.springframework.util.StringUtils;
|
|||||||
* <li>to use JUnit Platform
|
* <li>to use JUnit Platform
|
||||||
* <li>with a max heap of 1024M
|
* <li>with a max heap of 1024M
|
||||||
* <li>to run after any Checkstyle and format checking tasks
|
* <li>to run after any Checkstyle and format checking tasks
|
||||||
|
* <li>to enable retries with a maximum of three attempts when running on CI
|
||||||
|
* <li>to use predictive test selection when running locally
|
||||||
* </ul>
|
* </ul>
|
||||||
* <li>A {@code testRuntimeOnly} dependency upon
|
* <li>A {@code testRuntimeOnly} dependency upon
|
||||||
* {@code org.junit.platform:junit-platform-launcher} is added to projects with the
|
* {@code org.junit.platform:junit-platform-launcher} is added to projects with the
|
||||||
@ -164,15 +167,28 @@ class JavaConventions {
|
|||||||
test.setMaxHeapSize("1024M");
|
test.setMaxHeapSize("1024M");
|
||||||
project.getTasks().withType(Checkstyle.class, test::mustRunAfter);
|
project.getTasks().withType(Checkstyle.class, test::mustRunAfter);
|
||||||
project.getTasks().withType(CheckFormat.class, test::mustRunAfter);
|
project.getTasks().withType(CheckFormat.class, test::mustRunAfter);
|
||||||
TestRetryExtension testRetry = test.getExtensions().getByType(TestRetryExtension.class);
|
configureTestRetries(test);
|
||||||
testRetry.getFailOnPassedAfterRetry().set(true);
|
configurePredictiveTestSelection(test);
|
||||||
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
|
|
||||||
});
|
});
|
||||||
project.getPlugins()
|
project.getPlugins()
|
||||||
.withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
|
.withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
|
||||||
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
|
.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() {
|
private boolean isCi() {
|
||||||
return Boolean.parseBoolean(System.getenv("CI"));
|
return Boolean.parseBoolean(System.getenv("CI"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user