Vedavyas Bhat
Vedavyas Bhat

Reputation: 2108

Gradle multiprojects with same name, different paths

I have a monolith Gradle project that contains multiple subprojects, each with its own subprojects, like so:

project
  |
  |-- subprojectA
  |    |-- models
  |
  |-- subprojectB
  |    |-- models

This compiles fine but the issue is when I try to add a dependency on :subprojectB:models to :subprojectA:models, Gradle thinks :subprojectA:models is trying to add a dependency on itself and complains of a circular dependency, even though I specify the fully qualified path like so (in subprojectA's build.gradle):

compile project(':subprojectB:models')

How can I avoid this? Can subprojects not have the same name even if their paths are unique?

Upvotes: 3

Views: 1704

Answers (2)

sschuberth
sschuberth

Reputation: 29811

That's currently a known Gradle issue as Gradle by default uses the parent directory name as the project name. You can work around the issue as described here by assigning unique subproject names in the root project's settings.gradle like so:

include ':subprojectA:models-a', ':subprojectB:models-b'
project(':subprojectA:models-a').projectDir = file('subprojectA/models')
project(':subprojectB:models-b').projectDir = file('subprojectB/models')

Upvotes: 2

Louis Jacomet
Louis Jacomet

Reputation: 14500

Project identity for dependency resolution is based on the group:name:version or GAV coordinates, as explained in the linked Gradle issue.

So you need to make sure your different models project have different GAVs.

Upvotes: 2

Related Questions