Skip to content

Commit 9562a1c

Browse files
committed
Move build test configuration to Gradle convention
This commit moves the Gradle test configuration to a convention so it can be applied to all test tasks, including from other source sets. See gh-30339
1 parent ed4404f commit 9562a1c

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

build.gradle

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ configure([rootProject] + javaProjects) { project ->
6262
matching { it.name.endsWith("Classpath") }.all { it.extendsFrom(dependencyManagement) }
6363
}
6464

65-
test {
66-
useJUnitPlatform()
67-
include(["**/*Tests.class", "**/*Test.class"])
68-
systemProperty("java.awt.headless", "true")
69-
systemProperty("testGroups", project.properties.get("testGroups"))
70-
systemProperty("io.netty.leakDetection.level", "paranoid")
71-
systemProperty("io.netty5.leakDetectionLevel", "paranoid")
72-
systemProperty("io.netty5.leakDetection.targetRecords", "32")
73-
systemProperty("io.netty5.buffer.lifecycleTracingEnabled", "true")
74-
systemProperty("io.netty5.buffer.leakDetectionEnabled", "true")
75-
jvmArgs(["--add-opens=java.base/java.lang=ALL-UNNAMED",
76-
"--add-opens=java.base/java.util=ALL-UNNAMED"])
77-
}
78-
7965

8066
dependencies {
8167
dependencyManagement(enforcedPlatform(dependencies.project(path: ":framework-platform")))

buildSrc/src/main/java/org/springframework/build/TestConventions.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.build;
1818

19+
import java.util.Map;
20+
1921
import org.gradle.api.Project;
2022
import org.gradle.api.plugins.JavaBasePlugin;
2123
import org.gradle.api.tasks.testing.Test;
@@ -41,11 +43,36 @@ void apply(Project project) {
4143

4244
private void configureTestConventions(Project project) {
4345
project.getTasks().withType(Test.class,
44-
test -> project.getPlugins().withType(TestRetryPlugin.class, testRetryPlugin -> {
45-
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
46-
testRetry.getFailOnPassedAfterRetry().set(true);
47-
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
48-
}));
46+
test -> {
47+
configureTests(project, test);
48+
configureTestRetryPlugin(project, test);
49+
});
50+
}
51+
52+
private void configureTests(Project project, Test test) {
53+
test.useJUnitPlatform();
54+
test.include("**/*Tests.class", "**/*Test.class");
55+
test.setSystemProperties(Map.of(
56+
"java.awt.headless", "true",
57+
"io.netty.leakDetection.level", "paranoid",
58+
"io.netty5.leakDetectionLevel", "paranoid",
59+
"io.netty5.leakDetection.targetRecords", "32",
60+
"io.netty5.buffer.lifecycleTracingEnabled", "true"
61+
));
62+
if (project.hasProperty("testGroups")) {
63+
test.systemProperty("testGroups", project.getProperties().get("testGroups"));
64+
}
65+
test.jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED",
66+
"--add-opens=java.base/java.util=ALL-UNNAMED",
67+
"-Djava.locale.providers=COMPAT");
68+
}
69+
70+
private void configureTestRetryPlugin(Project project, Test test) {
71+
project.getPlugins().withType(TestRetryPlugin.class, testRetryPlugin -> {
72+
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
73+
testRetry.getFailOnPassedAfterRetry().set(true);
74+
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
75+
});
4976
}
5077

5178
private boolean isCi() {

0 commit comments

Comments
 (0)