My Java project is setup like this:
ProjectRoot
ModuleA
src
main
java
ModuleB
src
main
java
ModuleC
src
main
java
ModuleC is used to hold code that is common to both ModuleA and ModuleB. However, ModuleC also has code that references code in ModuleA and ModuleB. In effect, this is a circular reference. Note however, that when ModuleC does call APIs in ModuleA or ModuleB, no circular calls are actually made since the APIs themselves do not call anything in ModuleC. My gradle project fails because the code in ModuleC cannot resolve the dependencies for ModuleA and ModuleB.
For ModuleA the settings.gradle file look like this:
include 'ModuleA', ":ModuleC"
project(':ModuleC').projectDir = new File('../ModuleC')
For ModuleB the settings.gradle file look like this:
include 'ModuleB', ":ModuleC"
project(':ModuleC').projectDir = new File('../ModuleC')
In the build.gradle files for ModuleA and ModuleB I set the dependencies to:
dependencies {
compile project(':ModuleC')
}
But I cannot put this into ModuleC because it will create a circular dependency:
dependencies {
compile project(':ModuleA')
compile project(':ModuleC')
So what settings do I need to make to avoid circular dependencies?