Slackbot
12/06/2023, 3:15 PMephemient
12/06/2023, 3:18 PM// build.gradle.kts
tasks.register("foo") {
dependsOn(gradle.includedBuilds.map { it.task(":foo") })
}
// included/build.gradle.kts
tasks.register("foo") {
dependsOn(subprojects.map { "${it.path}:foo" })
}Adam
12/06/2023, 3:25 PMtask :foo?ephemient
12/06/2023, 3:27 PMAdam
12/06/2023, 3:27 PMtasks.register("foo") {
dependsOn(
subprojects.map { subproject ->
subproject.tasks.matching { it.name == "foo" }
}
)
}Vampire
12/06/2023, 3:28 PMVampire
12/06/2023, 3:29 PMtasks.matching like that completely disables task-configuration avoidance, you should not reach into the subprojects model like that. That's why ephemient did it with the string-y dependency.Adam
12/06/2023, 3:35 PM// modules/build.gradle.kts
// workaround for running <https://github.com/gradle/gradle/issues/22335>
tasks.addRule("Pattern: subprojectTasks_
<TASK>") {
val taskName = this
val taskPrefix = "subprojectTasks_"
if (startsWith(taskPrefix)) {
task(taskName) {
val buildTaskName = taskName.removePrefix(taskPrefix).replaceFirstChar(Char::lowercase)
val subprojectTasks = subprojects.map { subproject ->
subproject.tasks.matching { it.name == buildTaskName }
}
dependsOn(subprojectTasks)
}
}
}
which is basically the same functionality as https://github.com/gradle/gradle/issues/22335 👍Vampire
12/06/2023, 4:38 PM