mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Configure Gradle's Test Retry plugin
Closes gh-20144
This commit is contained in:
parent
33e6ab7a68
commit
9bdf4a75e8
@ -20,6 +20,7 @@ dependencies {
|
|||||||
implementation("org.apache.maven:maven-embedder:3.6.2")
|
implementation("org.apache.maven:maven-embedder:3.6.2")
|
||||||
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.0.0")
|
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.0.0")
|
||||||
implementation("org.asciidoctor:asciidoctor-gradle-jvm-pdf: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-core:5.2.2.RELEASE")
|
||||||
implementation("org.springframework:spring-web:5.2.2.RELEASE")
|
implementation("org.springframework:spring-web:5.2.2.RELEASE")
|
||||||
implementation("com.google.code.gson:gson:2.8.5")
|
implementation("com.google.code.gson:gson:2.8.5")
|
||||||
|
@ -56,6 +56,8 @@ import org.gradle.api.tasks.bundling.Jar;
|
|||||||
import org.gradle.api.tasks.compile.JavaCompile;
|
import org.gradle.api.tasks.compile.JavaCompile;
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||||
import org.gradle.api.tasks.testing.Test;
|
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.boot.build.testing.TestFailuresPlugin;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
@ -71,7 +73,8 @@ import org.springframework.util.FileCopyUtils;
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@code sourceCompatibility} is set to {@code 1.8}
|
* <li>{@code sourceCompatibility} is set to {@code 1.8}
|
||||||
* <li>{@link SpringJavaFormatPlugin Spring Java Format}, {@link CheckstylePlugin
|
* <li>{@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
|
||||||
* <li>{@link Test} tasks are configured to use JUnit Platform and use a max heap of 1024M
|
* <li>{@link Test} tasks are configured to use JUnit Platform and use a max heap of 1024M
|
||||||
* <li>{@link JavaCompile}, {@link Javadoc}, and {@link FormatTask} tasks are configured
|
* <li>{@link JavaCompile}, {@link Javadoc}, and {@link FormatTask} tasks are configured
|
||||||
* to use UTF-8 encoding
|
* to use UTF-8 encoding
|
||||||
@ -139,10 +142,16 @@ public class ConventionsPlugin implements Plugin<Project> {
|
|||||||
javadoc.getOptions().source("1.8").encoding("UTF-8");
|
javadoc.getOptions().source("1.8").encoding("UTF-8");
|
||||||
withOptionalBuildJavaHome(project, (javaHome) -> javadoc.setExecutable(javaHome + "/bin/javadoc"));
|
withOptionalBuildJavaHome(project, (javaHome) -> javadoc.setExecutable(javaHome + "/bin/javadoc"));
|
||||||
});
|
});
|
||||||
|
project.getPlugins().apply(TestRetryPlugin.class);
|
||||||
project.getTasks().withType(Test.class, (test) -> {
|
project.getTasks().withType(Test.class, (test) -> {
|
||||||
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
||||||
test.useJUnitPlatform();
|
test.useJUnitPlatform();
|
||||||
test.setMaxHeapSize("1024M");
|
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.getTasks().withType(Jar.class, (jar) -> {
|
||||||
project.afterEvaluate((evaluated) -> {
|
project.afterEvaluate((evaluated) -> {
|
||||||
|
@ -24,6 +24,7 @@ import java.io.PrintWriter;
|
|||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.GradleRunner;
|
import org.gradle.testkit.runner.GradleRunner;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -74,8 +75,29 @@ class ConventionsPluginTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runGradle(String... args) {
|
@Test
|
||||||
GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user