I am migrating a Java project from Ant to Gradle. I believe the best solution is to support Gradle multi-project support, but I cannot find a way to get rid of the circular dependency.
The initial design was set up this way:
- project/ - common/ - product-a/ - product-b/
The relationship between common , product-a and product-b complex. common depends on product-a or product-b , depending on the configuration file. Similarly, product-a and product-b depend on common , regardless of the configuration property. product-a and product-b will never be created at the same time.
I thought a quick solution would be to use something like this in project/build.gradle :
project(':product-a') { dependencies { compile project(':common') } } project(':product-b') { dependencies { compile project(':common') } }
Then I thought about finding a way to get closer to work only for the product-a . This led me to the following:
project(':common') { dependencies { compile project(':product-a') } }
This will throw an exception for circular dependency.
I considered refactoring product-a and product-b by setting the class interfaces expected by common and product-a / product-b , or using polymorphism, but before I go any further with any of them, is there a better way to do this with Gradle? I am not yet ready to get rid of this technical debt.
source share