Multi-module subproject dependent on each other in Gradle

Viewed 737

I have a question regarding multi-module sub project in Gradle, can sub probject dependent on each other?

For example the following project:

root
|___ project1
|___ project2
|___ project3

Can project1 and project2 dependent on each other?

in build.gradle of project1:

dependencies {
       compile project(':project2')
}

in build.gradle of project2:

dependencies {
       compile project(':project1')
}

I am new to gradle, does this work?

1 Answers

Does it work ?

Short answer : no

Detailed answer :

It's not specific to Gradle and it's called circular dependencies. It's bad and it prevents the compilation. project1 needs project2 so it will require project2 to be built before. project2 needs project1 so it will require project1 to be built before. Do you see the issue ?

There is many ways to solve circular dependencies, depending of your architecture. In your simple example, maybe project1 and project2 should belong to the same project.

Related