Skip to content

Commit 01210df

Browse files
authored
Fix running ./gradlew tasks (#11692)
1 parent 3cf1a90 commit 01210df

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

build.gradle.kts

+38-38
Original file line numberDiff line numberDiff line change
@@ -49,56 +49,56 @@ if (project.findProperty("skipTests") as String? == "true") {
4949
}
5050
}
5151

52-
tasks {
53-
val listTestsInPartition by registering {
54-
group = "Help"
55-
description = "List test tasks in given partition"
56-
57-
// total of 4 partitions (see modulo 4 below)
58-
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
59-
if (testPartition == null) {
60-
throw GradleException("Test partition must be specified")
61-
} else if (testPartition < 0 || testPartition >= 4) {
62-
throw GradleException("Invalid test partition")
63-
}
52+
if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
53+
tasks {
54+
val listTestsInPartition by registering {
55+
group = "Help"
56+
description = "List test tasks in given partition"
57+
58+
// total of 4 partitions (see modulo 4 below)
59+
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
60+
if (testPartition == null) {
61+
throw GradleException("Test partition must be specified")
62+
} else if (testPartition < 0 || testPartition >= 4) {
63+
throw GradleException("Invalid test partition")
64+
}
6465

65-
val partitionTasks = ArrayList<Test>()
66-
var testPartitionCounter = 0
67-
subprojects {
68-
// relying on predictable ordering of subprojects
69-
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
70-
// since we are splitting these tasks across different github action jobs
71-
val enabled = testPartitionCounter++ % 4 == testPartition
72-
if (enabled) {
73-
tasks.withType<Test>().configureEach {
74-
partitionTasks.add(this)
66+
val partitionTasks = ArrayList<Test>()
67+
var testPartitionCounter = 0
68+
subprojects {
69+
// relying on predictable ordering of subprojects
70+
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
71+
// since we are splitting these tasks across different github action jobs
72+
val enabled = testPartitionCounter++ % 4 == testPartition
73+
if (enabled) {
74+
tasks.withType<Test>().configureEach {
75+
partitionTasks.add(this)
76+
}
7577
}
7678
}
77-
}
7879

79-
doLast {
80-
File("test-tasks.txt").printWriter().use { writer ->
81-
partitionTasks.forEach { task ->
82-
var taskPath = task.project.path + ":" + task.name
83-
// smoke tests are run separately
84-
// :instrumentation:test runs all instrumentation tests
85-
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
86-
writer.println(taskPath)
80+
doLast {
81+
File("test-tasks.txt").printWriter().use { writer ->
82+
partitionTasks.forEach { task ->
83+
var taskPath = task.project.path + ":" + task.name
84+
// smoke tests are run separately
85+
// :instrumentation:test runs all instrumentation tests
86+
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
87+
writer.println(taskPath)
88+
}
8789
}
8890
}
8991
}
90-
}
9192

92-
// disable all tasks to stop build
93-
subprojects {
94-
tasks.configureEach {
95-
enabled = false
93+
// disable all tasks to stop build
94+
subprojects {
95+
tasks.configureEach {
96+
enabled = false
97+
}
9698
}
9799
}
98100
}
99-
}
100101

101-
if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
102102
// disable all tasks to stop build
103103
project.tasks.configureEach {
104104
if (this.name != "listTestsInPartition") {

0 commit comments

Comments
 (0)