Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle multiprojects with same name, different paths

Tags:

gradle

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?

like image 574
Vedavyas Bhat Avatar asked Dec 01 '25 07:12

Vedavyas Bhat


2 Answers

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.

  • One way to make this happen is to make the subprojectA (or B) part of the group.
  • Another way is to assign names that are not based on the containing folder.
like image 165
Louis Jacomet Avatar answered Dec 03 '25 00:12

Louis Jacomet


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')
like image 30
sschuberth Avatar answered Dec 03 '25 01:12

sschuberth