Sergej Koščejev
07/03/2024, 7:54 AM./gradlew check on a root project of a multi-project build, it will run the check task of all projects. How do I create a Gradle task that runs this? Is something like this correct (Kotlin syntax) or are there pitfalls? Should I use a provider in dependsOn?
tasks.register("myCheck") {
dependsOn(allprojects.mapNotNull { it.tasks.findByPath("check") })
}melix
07/03/2024, 8:45 AMmelix
07/03/2024, 8:45 AM./gradlew foo, it will execute the foo task on all projects which define itmelix
07/03/2024, 8:46 AM./gradlew :foo it will only execute it on the root projectSergej Koščejev
07/03/2024, 8:46 AMmelix
07/03/2024, 8:46 AMmyCheck in all projectsmelix
07/03/2024, 8:47 AMSergej Koščejev
07/03/2024, 8:48 AMSergej Koščejev
07/03/2024, 8:48 AMmelix
07/03/2024, 8:49 AMval myCheck = tasks.register("myCheck") {
}
pluginManager.withPlugin("should-disable-checks") { myCheck.configure { enabled = false }Sergej Koščejev
07/03/2024, 9:06 AMmelix
07/03/2024, 9:07 AMmelix
07/03/2024, 9:07 AMSergej Koščejev
07/03/2024, 9:08 AM./gradlew check also forcefully configure tasks? it has to figure out which projects have the task and which don't, after all.Vampire
07/03/2024, 9:31 AMtasks.register("myCheck") {
allprojects.filterNot { it.path == ":notInThisProject" }.forEach { dependsOn("${it.path}:check") }
}
or
tasks.register("myCheck") {
dependsOn(":inThis:check")
dependsOn(":andAlsoThis:check")
}
as the project path is already known at that time and by using the string-y dependsOn, it is evaluated late and without cross-project model access.Sergej Koščejev
07/03/2024, 9:49 AMprovider to make it a bit lazier, just to be sure), and my understanding is that using allprojects, especially in a provider, is not doing any more work or causing any more initialization/evaluation/configuration compared to ./gradlew check. Am I wrong? Which optimizations would it disturb, compared to ./gradlew check?Vampire
07/03/2024, 11:21 AM./gradlew check -P onlyFastTests=true and then accordingly enable / disable tasks as necessary. Disabling check for example would be pointless, as check is a lifecycle task that anyway in almost all cases does not have own actions anyway and disabling a task does not disable its dependency tasks, so you probably instead need to disable test or whatever you want to not run.Sergej Koščejev
07/03/2024, 1:45 PM