This message was deleted.
# community-support
s
This message was deleted.
v
No, mainly the cross-project configuration is bad. Collecting information should be ok I think. But on the other hand, things like
Copy code
dependencies { implementation subprojects[0].tasks.someOtherJar }
are very bad, even worse than cross-project configuration
❤️ 1
1
m
the next I do in custom plugin is actually
Copy code
custom 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.
j
Even for collecting information you break project isolation right?
m
I'm doing this for "aggregation": i need to run a task that would depend on every subproject's particular task
j
What you are doing should be done like the new test aggregator plugin does but I would like to see a really tiny example of it, I asked some time ago but I got no reply I think
v
I don't think the test aggregation plugin pattern applies, as he does not want to get reports or other ouptut from these tasks. Afair just for
dependsOn
it might be fine.
Or does that task that depends on the others use some output of them? Then what you do is exactly what is bad.
m
my custom task depends on subprojects' tasks only to enforce running them in order. So, my custom task is kind of "lifecycle" task. It doesn't use any output, because subprojects' tasks would generate all input I need themselves.
in particular, I just need to run
ktlintCheck
for each subproject, but I'd like to do so in one command:
ktlintCheckAll
(my task)
btw, if you say that depending on subprojects' tasks OUTPUTS is bad - is there any good way to depend on outputs?
j
running ktLintCheck already runs it in all subprojects
m
ok but my question is how to make my custom tasks
j
what is your task doing
m
running all tasks for the specified name for all subprojects
v
what custom tasks? If you run
gradlew 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 subprojects
2
m
by depending on them
v
btw, 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
m
makes sense
m
If you run
gradlew 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.
this works from CLI but what if I would like to run a task, that would involve subprojects' tasks?
Copy code
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
:
Copy code
tasks.register("ktlintCheckAll").configure {
    rootProject.subprojects.flatMap {
  it.tasks.withType(BaseKtLintCheckTask).matching { t -> t.name == "ktlintCheck" }
}

}
thus,
Copy code
root build.gradle

tasks.register("staticAnalysis") {
    dependsOn(tasks.named("ktlintCheckAll"))
}
to enforce running all
ktlintCheck
for all subprojects
j
you need all sub projects
ktLintCheck
task depends on a
staticAnalysis
task registered in each sub project
so you don't need a root
staticAnalysis
task
you will have that task per module, and when you run that task without passing the module, all your
staticAnalysis
tasks will be executed
m
makes sense but still - what if I want a "root" task. How to do so? Am I right?
what you mean is that i have to run the task explicitly w/o specifying a module
j
yeah
same way ktlintCheck is working in all modules when you run it via CLI when you don't indicate a module, all your tasks in all modules will run, and consequently ktlinCheck tasks will run too, if you invoke your task without indicating the module
m
ok, how to express the intention that I would like to run a task w/o indicating a module, in build.gradle script?
whatever I write would always refer to a project.tasks and a particular task, hence - it would always "indicate a module"
j
I don't understand what you mean
running a CLI command from gradle build script?
m
how to express
./gradlew ktlintCheck
instead of
./gradlew :ktlintCheck
in gradle scripts?
j
I think you are mixing things
you should build "second" in build files, and you can use one or second based on your needs
m
that means I cannot use "first" in build scripts
v
Exactly. Well, you need
subprojects
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.
❤️ 1