I am migrating a Java project from Ant to Gradle. I think the best solution is to use Gradle's multi-project support, but I cannot find a way to get rid of a circular dependency.
The original project was setup to have this layout:
- project/
- common/
- product-a/
- product-b/
The relationship between common, product-a, and product-b is tricky. The common depends on product-a or product-b, depending on a configuration file. Likewise, product-a and product-b depend on common, regardless of the configuration property. product-a and product-b will never be built at the same time.
I thought a quick solution would be to use something like this in the project/build.gradle:
project(':product-a') {
dependencies {
compile project(':common')
}
}
project(':product-b') {
dependencies {
compile project(':common')
}
}
Next, I thought about getting a way to get this closer to working for just product-a. That led me to this:
project(':common') {
dependencies {
compile project(':product-a')
}
}
This will throw an exception for having a circular dependency.
I've considered refactoring product-a and product-b by setting up interfaces of the classes expected by common and product-a/product-b or by using polymorphism, but before I move forward with either of those, is there a better way to accomplish this with Gradle? I'm not ready to get rid of this technical debt yet.