Debian Codegraph @

gradle/plugins/common/src/main/kotlin/junitbuild.testing-conventions.gradle.kts

raw
1 import com.gradle.enterprise.gradleplugin.testretry.retry
2 import com.gradle.enterprise.gradleplugin.testselection.internal.PredictiveTestSelectionExtensionInternal
3 import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
4 import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
5 import org.gradle.internal.os.OperatingSystem
6
7 plugins {
8 `java-library`
9 id("junitbuild.build-parameters")
10 }
11
12 tasks.withType<Test>().configureEach {
13 useJUnitPlatform {
14 includeEngines("junit-jupiter")
15 }
16 include("**/*Test.class", "**/*Tests.class")
17 testLogging {
18 events = setOf(FAILED)
19 exceptionFormat = FULL
20 }
21 retry {
22 maxRetries = buildParameters.testing.retries.orElse(if (buildParameters.ci) 2 else 0)
23 }
24 distribution {
25 enabled.convention(buildParameters.junit.develocity.testDistribution.enabled && (!buildParameters.ci || System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY").isNotBlank()))
26 maxLocalExecutors = buildParameters.junit.develocity.testDistribution.maxLocalExecutors
27 maxRemoteExecutors = buildParameters.junit.develocity.testDistribution.maxRemoteExecutors
28 if (buildParameters.ci) {
29 when {
30 OperatingSystem.current().isLinux -> requirements.add("os=linux")
31 OperatingSystem.current().isWindows -> requirements.add("os=windows")
32 OperatingSystem.current().isMacOsX -> requirements.add("os=macos")
33 }
34 }
35 }
36 predictiveSelection {
37 enabled = buildParameters.junit.develocity.predictiveTestSelection.enabled
38
39 // Ensure PTS works when publishing Build Scans to scans.gradle.com
40 this as PredictiveTestSelectionExtensionInternal
41 server = uri("https://ge.junit.org")
42 }
43 systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
44 // Required until ASM officially supports the JDK 14
45 systemProperty("net.bytebuddy.experimental", true)
46 if (buildParameters.testing.enableJFR) {
47 jvmArgs(
48 "-XX:+UnlockDiagnosticVMOptions",
49 "-XX:+DebugNonSafepoints",
50 "-XX:StartFlightRecording=filename=${reports.junitXml.outputLocation.get()},dumponexit=true,settings=profile.jfc",
51 "-XX:FlightRecorderOptions=stackdepth=1024"
52 )
53 }
54
55 // Track OS as input so that tests are executed on all configured operating systems on CI
56 trackOperationSystemAsInput()
57
58 // Avoid passing unnecessary environment variables to the JVM (from GitHub Actions)
59 if (buildParameters.ci) {
60 environment.remove("RUNNER_TEMP")
61 environment.remove("GITHUB_ACTION")
62 }
63
64 jvmArgumentProviders += CommandLineArgumentProvider {
65 listOf(
66 "-Djunit.platform.reporting.open.xml.enabled=true",
67 "-Djunit.platform.reporting.output.dir=${reports.junitXml.outputLocation.get().asFile.absolutePath}"
68 )
69 }
70 }
71
72 dependencies {
73 testImplementation(dependencyFromLibs("assertj"))
74 testImplementation(dependencyFromLibs("mockito"))
75 testImplementation(dependencyFromLibs("testingAnnotations"))
76
77 if (!project.name.startsWith("junit-jupiter")) {
78 testImplementation(project(":junit-jupiter"))
79 }
80
81 testRuntimeOnly(project(":junit-platform-engine"))
82 testRuntimeOnly(project(":junit-platform-jfr"))
83 testRuntimeOnly(project(":junit-platform-reporting"))
84
85 testRuntimeOnly(bundleFromLibs("log4j"))
86 testRuntimeOnly(dependencyFromLibs("openTestReporting-events")) {
87 because("it's required to run tests via IntelliJ which does not consumed the shadowed jar of junit-platform-reporting")
88 }
89 }