How to enable circular dependency in Gradle

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.

+5
source share
1 answer

Removing a circular dependency cannot be resolved by cheating the assembly. You will have to reorganize your modules so that there is no more cyclic dependency. From your module names and without any other information, I would think that you would want to extract a part of the “general” that depends on “product- *” and put it in a new module.

+5
source

All Articles