I have a project that consists of multiple sub-projects. The project’s root directory is called “tools”.
Multi-Project Build Basics says:
Finally, you can build and test everything in all projects. Any task you run in the root project folder will cause that same-named task to be run on all the children.
That works. From the root project directory I can run a task (like “test”) and that task is run on all the children.
Now I includeBuild
this project in another project, such that “:tools” is the reference to the included project.
If, from the root directory of the other project, I run a task that is a “root” task of the included project it no longer runs on all the child projects in the included project.
I.e.,
tools% ../gradlew test # <-- works, runs "test" in all child projects
tools% cd ..
% ./gradlew :tools:test # <-- only runs "test" in root "tools" project, not child projects
- Is this intended behaviour? I can’t find it documented anywhere, and it’s extremely weird that running a task has different results depending on the directory you’re in when you run it.
- If this is intended behaviour, is there a straightforward workaround?
I can, for example, ensure that test
dependencies are always run with something like this in tools/build.gradle.kts
:
tasks.named<Test>("test").configure {
subprojects.forEach { subproject ->
subproject.tasks.withType<Test>().forEach {
this.finalizedBy(it)
}
}
}
but this only works for tasks of type Test
, and does not match the “Any task you run in the root project folder will cause that same-named task to be run on all the children.” behaviour.