Search code examples
gradlebuilddependencies

how to do gradle dependency project to each other


Good day,

Previously I was using eclipse IDE to do the project dependency. So my project A can import class from project B, and also project B can import project A.

Now I am changing to gradle. The following is my gradle code:

project('host-A') {

  dependencies {
    compile project(':host-B')
  }
  host.ext.A = project
}

With this, my project A able to import class from project B.

However, I wish to make the project B able to import class from project A as well, but I am hitting error if I code the gradle as follow:

project('host-B') {

  dependencies {

   compile project(':host-A')

  }
  host.ext.B = project
}

I believe there should be a way to do this. May I know what is my mistake? I am new to gradle.


Solution

  • I believe there should be a way to do this.

    There is none. Cyclic dependencies only work in Gradle if the configuration itself is cyclic free, for example: Project A has a compile dependency to B and B has a testCompile dependency to A. Both depending on each other for compile won't work.

    Maybe you can rework your project setup? It is quite common to extract base functionality into separate projects, say project C. This way both A and B could depend on C without depending on each other.