With project isolation, is it ok to access root pr...
# community-support
e
With project isolation, is it ok to access root project lifecycle tasks from a sub project? e.g.
rootProject.tasks.named("check").configure { dependsOn(myTask) }
m
I'd vote "no".
p
It's not, but you can either define it as the other way in your root project, via hardcoded tasks or aggregation, or use a settings plugin. BTW there are no real lifecycle tasks, it is only a convention, but you can add actions to a „lifecycle“ task.
1
e
I'm not sure I follow. How would I do it from the root project or a settings plugin if I need to access the task from the subproject?
m
Copy code
tasks.named("check").configure {
  it.dependsOn(":module:myTask")
}
👍 1
I think this works and is pi-safe
But otherwise you can do the whole aggregation dance and outgoing variants
You define an artifact built by "myTask" with a "good" attribute and you add "module" to the root project dependencies
t
so usually you would define a 'check' task in every project. if for some reason it needs to be a single task it gets a bit tricky
plus1 1
e
Oh interesting. So I'd make a
check
task in each subproject, and hardcode that in the root using
subprojects
?
m
3 solutions 😄
t
you make a check task in every project. than you can call ./gradlew check and that executes all the checks
but ./gradlew :checks only executes the checks in the root project
e
Good point 😅
p
Yeah, but this will configure all projects, if configure on demand is not a requirement.
t
well if your root project depends on all project it will also configure all projects 😄
p
Yeah sure, if you depend on all projects. But depending on all projects is not always the case, but it depends on your setup.
t
oh you right i read that wrong..
ok so you dont make a "check" task in every project, only in those projects that have a "mytask" task
m
There's like 95% chance there's a check task in each subproject though. Java, Android and Kotlin plugins all add it (from base lifecycle plugin or so)
t
yup
p
It really depends on the setup, you need to test what's better, regarding performance vs effort (to maintain an explicit list).
plus1 1