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.ktshas the following content:Each
build.gradle.ktshas acalltask 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:callwhen building. The twodependsOninside thecalldefinition forAinvoke the subprojectcalltasks.There is a similar structure available for
B.When running
gradle buildat root level, this is the output I get:When running
gradle buildinside theAsubproject, I get:When running it inside
:A:C, I don't get any output because I haven't specified thatC'sbuildtask 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.