@@ -37,9 +37,14 @@ val skipTestsProvider = rootProject.providers.gradleProperty("skipTests")
3737val skipForkedTestsProvider = rootProject.providers.gradleProperty(" skipForkedTests" )
3838val skipFlakyTestsProvider = rootProject.providers.gradleProperty(" skipFlakyTests" )
3939val runFlakyTestsProvider = rootProject.providers.gradleProperty(" runFlakyTests" )
40+ val activePartitionProvider = providers.provider {
41+ project.extra.properties[" activePartition" ] as ? Boolean ? : true
42+ }
4043
4144// Go through the Test tasks and configure them
4245tasks.withType(Test ::class .java).configureEach {
46+ enabled = activePartitionProvider.get()
47+
4348 // Disable all tests if skipTests property was specified
4449 onlyIf { ! skipTestsProvider.isPresent }
4550
@@ -83,52 +88,42 @@ tasks.withType(Test::class.java).configureEach {
8388 timeout.set(Duration .of(20 , ChronoUnit .MINUTES ))
8489}
8590
86- val allTestsTask = tasks.maybeCreate(" allTests" )
87- val allLatestDepTestsTask = tasks.maybeCreate(" allLatestDepTests" )
88- val checkTask = tasks.named(" check" )
89-
90- project.afterEvaluate {
91- tasks.withType(Test ::class .java).forEach {
92- // Add test to appropriate aggregate task
93- if (it.name.contains(" latest" , ignoreCase = true )) {
94- allLatestDepTestsTask.dependsOn(it)
95- } else if (it.name != " traceAgentTest" ) {
96- allTestsTask.dependsOn(it)
91+ tasks.register(" allTests" ) {
92+ dependsOn(providers.provider {
93+ tasks.withType<Test >().filter { testTask ->
94+ ! testTask.name.contains(" latest" , ignoreCase = true ) && testTask.name != " traceAgentTest"
9795 }
96+ })
97+ }
9898
99- checkTask.configure {
100- dependsOn(it)
99+ tasks.register(" allLatestDepTests" ) {
100+ dependsOn(providers.provider {
101+ tasks.withType<Test >().filter { testTask ->
102+ testTask.name.contains(" latest" , ignoreCase = true )
101103 }
102- }
104+ })
103105}
104106
105- // Setup flaky tests jobs. Done in afterEvaluate so that it applies to latestDepTest.
106- project.afterEvaluate {
107- tasks.withType(Test ::class .java).configureEach {
108- // Flaky tests management for JUnit 5
109- if (testFramework is JUnitPlatformOptions ) {
110- val junitPlatform = testFramework as JUnitPlatformOptions
111- if (skipFlakyTestsProvider.isPresent) {
112- junitPlatform.excludeTags(" flaky" )
113- } else if (runFlakyTestsProvider.isPresent) {
114- junitPlatform.includeTags(" flaky" )
115- }
116- }
107+ tasks.named(" check" ) {
108+ dependsOn(tasks.withType<Test >())
109+ }
117110
118- // Flaky tests management for Spock
111+ tasks.withType(Test ::class .java).configureEach {
112+ // Flaky tests management for JUnit 5
113+ if (testFramework is JUnitPlatformOptions ) {
114+ val junitPlatform = testFramework as JUnitPlatformOptions
119115 if (skipFlakyTestsProvider.isPresent) {
120- jvmArgs( " -Drun. flaky.tests=false " )
116+ junitPlatform.excludeTags( " flaky" )
121117 } else if (runFlakyTestsProvider.isPresent) {
122- jvmArgs( " -Drun. flaky.tests=true " )
118+ junitPlatform.includeTags( " flaky" )
123119 }
124120 }
125- }
126121
127- if ( ! (project.property( " activePartition " ) as Boolean )) {
128- project.afterEvaluate {
129- tasks.withType( Test :: class .java).configureEach {
130- enabled = false
131- }
122+ // Flaky tests management for Spock
123+ if (skipFlakyTestsProvider.isPresent) {
124+ jvmArgs( " -Drun.flaky.tests=false " )
125+ } else if (runFlakyTestsProvider.isPresent) {
126+ jvmArgs( " -Drun.flaky.tests=true " )
132127 }
133128}
134129
0 commit comments