I am having troubles with seting up 3 level gradle multi-project:
Level_1_Proj
│
├── Level_2_Proj_A
│ │
│ ├── Level_3_Proj_C
│ └── Level_3_Proj_D
│
└── Level_2_Proj_B
│
├── Level_3_Proj_E
└── Level_3_Proj_F
I would like to be able to:
- set up dependencies between projects of the same level in the build script, like:
dependencies {
project('Level_2_Proj_A') {
dependencies {
implementation project('Level_2_Proj_B')
}
}
}
- also want to be able to build (the subtree) starting the bash command [$gradle build] at any level [then build down the projects' subtree]
I have achieved building from the middle and bottom levels, but I cannot setup the build from the top level. Getting error:
A problem occurred evaluating project ‘Level_2_Proj_A’. Project with path ‘Level_3_Proj_C’ could not be found in project ‘Level_2_Proj_A’.
Is it possible? If so, how to configure? Thanks
Alright, here's how I managed to get it working. Given the following directory structure:
The
settings.gradle.kts
has the following content:Each
build.gradle.kts
has acall
task that prints the name path of the project, e.g. Inside the C project:Inside the A project:
The
tasks["build"].dependsOn(":A:call")
tells Gradle to invoke:A:call
when building. The twodependsOn
inside thecall
definition forA
invoke the subprojectcall
tasks.There is a similar structure available for
B
.When running
gradle build
at root level, this is the output I get:When running
gradle build
inside theA
subproject, I get:When running it inside
:A:C
, I don't get any output because I haven't specified thatC
'sbuild
task should depend oncall
, but that could easily be done. Let me know if this doesn't work for you. I've used the Kotlin DSL for gradle, but you're perfectly free to change it to the Groovy variant.