How can I exclude parent defined compile project
dependency?
Structure of modules is as follows:
- build.gradle
- settings.gradle
- MAIN_MODULE_1
- build.gradle
- MODULE1
- build.gradle
- MODULE2
- build.gradle
- MODULE3
- build.gradle
- MODULE4
- build.gradle
And dependency model should be:
- MODULE1 <- MAIN_MODULE_1
- MODULE2 <- MAIN_MODULE_1
- MODULE3 <- MAIN_MODULE_1
- MODULE4 <- MAIN_MODULE_1
Which means, having
// build.gradle
subprojects {
apply plugin: 'java'
dependencies {
compile project('MAIN_MODULE_1')
}
}
// settings.gradle
include ':MAIN_MODULE_1'
include ':MODULE1'
include ':MODULE2'
include ':MODULE3'
include ':MODULE4'
will create circular dependency of MAIN_MODULE_1
on itself, which is wrong.
and having the dependency in each module (of total count not 4 but 120) seems wrong to me.
You can use the configuration block :
project(':MAIN_MODULE_1') {
apply plugin: 'java'
}
configure(subprojects - project(':MAIN_MODULE_1')) {
apply plugin: 'java'
dependencies {
compile project('MAIN_MODULE_1')
}
}
The answer is coming from this other question Gradle exclude plugin in main project for specific subproject(s)
You can conditionally apply the dependency only if you are not in project MAIN_MODULE_1
:
dependencies {
if (!project.name.equals("MAIN_MODULE_1")) {
compile project(':MAIN_MODULE_1')
}
}
The answer below is a cleaner solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With