Slackbot
05/31/2022, 11:24 AMVampire
05/31/2022, 11:34 AMdependencies { implementation subprojects[0].tasks.someOtherJar }
are very bad, even worse than cross-project configurationMaxim Alov
05/31/2022, 11:37 AMcustom task ...
dependsOn(subprojectsTasks)
but this is not a dependencies {}
. This custom plugin and custom tasks are supposed to be running occasionally.
I believe, your example means smth different. In my case, there is no project dependencies obtained this way. But here is a custom task that should depend on subprojects' tasks given by name.Javi
05/31/2022, 11:40 AMMaxim Alov
05/31/2022, 11:41 AMJavi
05/31/2022, 11:42 AMJavi
05/31/2022, 11:43 AMVampire
05/31/2022, 12:17 PMdependsOn
it might be fine.Vampire
05/31/2022, 12:18 PMVampire
05/31/2022, 12:18 PMMaxim Alov
05/31/2022, 12:23 PMMaxim Alov
05/31/2022, 12:24 PMktlintCheck
for each subproject, but I'd like to do so in one command:
ktlintCheckAll
(my task)Maxim Alov
05/31/2022, 12:25 PMJavi
05/31/2022, 12:25 PMMaxim Alov
05/31/2022, 12:26 PMJavi
05/31/2022, 12:27 PMMaxim Alov
05/31/2022, 12:27 PMVampire
05/31/2022, 12:27 PMgradlew ktLintCheck
, Gradle searches for this task in all projects and executes them.
If you run gradlew :ktLintCheck
it only runs it in the root project.
So what Javi meant is, that you don't need to add a lifecycle task just to run the same-named task in all subprojectsMaxim Alov
05/31/2022, 12:27 PMVampire
05/31/2022, 12:28 PMbtw, if you say that depending on subprojects' tasks OUTPUTS is bad - is there any good way to depend on outputs?I just gave you the link
Maxim Alov
05/31/2022, 12:28 PMVampire
05/31/2022, 12:28 PMMaxim Alov
06/01/2022, 9:46 AMIf you run, Gradle searches for this task in all projects and executes them.gradlew ktLintCheck
If you runthis works from CLI but what if I would like to run a task, that would involve subprojects' tasks?it only runs it in the root project.gradlew :ktLintCheck
root build.gradle
tasks.register("staticAnalysis") {
dependsOn(tasks.named("ktlintCheck"))
}
i believe (and I actually observe) that this won't run ktlintCheck
for each subproject: it only runs it for root project. That's why I add ktlintCheckAll
:
tasks.register("ktlintCheckAll").configure {
rootProject.subprojects.flatMap {
it.tasks.withType(BaseKtLintCheckTask).matching { t -> t.name == "ktlintCheck" }
}
}
thus,
root build.gradle
tasks.register("staticAnalysis") {
dependsOn(tasks.named("ktlintCheckAll"))
}
to enforce running all ktlintCheck
for all subprojectsJavi
06/01/2022, 9:48 AMktLintCheck
task depends on a staticAnalysis
task registered in each sub projectJavi
06/01/2022, 9:49 AMstaticAnalysis
taskJavi
06/01/2022, 9:49 AMstaticAnalysis
tasks will be executedMaxim Alov
06/01/2022, 9:53 AMMaxim Alov
06/01/2022, 9:54 AMJavi
06/01/2022, 9:55 AMJavi
06/01/2022, 9:56 AMMaxim Alov
06/01/2022, 9:56 AMMaxim Alov
06/01/2022, 9:57 AMJavi
06/01/2022, 10:01 AMJavi
06/01/2022, 10:01 AMMaxim Alov
06/01/2022, 10:01 AM./gradlew ktlintCheck
instead of ./gradlew :ktlintCheck
in gradle scripts?Javi
06/01/2022, 10:02 AMJavi
06/01/2022, 10:03 AMMaxim Alov
06/01/2022, 10:04 AMVampire
06/01/2022, 11:49 AMsubprojects
to do it, but usually this should simply not necessary. Why do you want to have a root task that depends on all subproject tasks? Just when you invoke, invoke the right one.