[GRADLE-3202] Project dependencies are cross-linked when project name's match, but project paths differ. Created: 21/Nov/14  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 0


 Description   

When I have a project with the following structure, I get weird dependency trees.

├── app
│ ├── businesslogic
│ │ ├── api
│ │ └── impl
│ └── infrastructure
│ └── domainmodel
│ ├── api
│ └── impl

The dependencies between the projects are as follows:

  • :app:businesslogic:impl depends on :app:businesslogic:api
  • :app:domainmodel:api depends on :app:businesslogic:api
  • :app:domainmodel:impl depends on :app:domainmodel:api
  • :app:domainmodel:impl depends on :app:businesslogic:impl

When I run the gradle command `gradle :app:infrastructure:domainmodel:impl:dependencies --configuration compile`, I receive the following output:

------------------------------------------------------------
Project :app:infrastructure:domainmodel:impl
------------------------------------------------------------

compile - Compile classpath for source set 'main'.
+--- project :app:businesslogic:impl

--- project :app:businesslogic:api
--- project :app:infrastructure:domainmodel:api
--- project :app:businesslogic:api

At this point, everything functions as expected. However, if I set the group to something like `com.mycompany`, I get strange dependency trees that look like this:

------------------------------------------------------------
Project :app:infrastructure:domainmodel:impl
------------------------------------------------------------

compile - Compile classpath for source set 'main'.
+--- project :app:businesslogic:impl -> project :app:infrastructure:domainmodel:impl
--- project :app:infrastructure:domainmodel:api
--- project :app:businesslogic:api -> project :app:infrastructure:domainmodel:api

I realize that this is probably due to the fact that items are stored within the dependency store using the key of group and name, but this forces me to resolve the problem in one of two ways:

1. Modify my directory structure to contain unique leaf nodes in my directory structure. Although this might be the "Gradle-way" it creates a problem when migrating an existing legacy Maven project.
1. Modify the way I create the projects with the unmanageable project declaration method (see below)

include 'app:businesslogic:api-A'
include 'app:businesslogic:impl-A'
include 'app:infrastructure:domainmodel:api-B'
include 'app:infrastructure:domainmodel:impl-B'

project('app:businesslogic:api-A').projectDir = "$rootDir/app/businesslogic/api" as File
project('app:businesslogic:impl-A').projectDir = "$rootDir/app/businesslogic/impl" as File
project('app:infrastructure:domainmodel:api-B').projectDir = "$rootDir/app/domainmodel/api" as File
project('app:infrastructure:domainmodel:impl-B').projectDir = "$rootDir/app/domainmodel/impl" as File

What am I doing wrong?



 Comments   
Comment by Gradle Forums [ 21/Nov/14 ]

according to the Gradle documentation, the definition of a `Project.name` is:

> The name of this project. The project's _name is not necessarily unique within a project hierarchy_. You should use the `Project.getPath()` method for a unique identifier for the project.

This is at odds with the way dependency resolution is operating for inner-project dependencies. Since a project's name is not necessarily unique within a project hierarchy, the dependency resolution cannot use the project name or it must incorporate some other identifier to uniquely identify the project. Ironically, you MUST specify inner-project dependencies using the project path, which is unique.

Comment by Gradle Forums [ 21/Nov/14 ]

Do you need to have the same group for your businesslogic and infrastructure subprojects? When you go to publish those artifacts, they'll have the same group and artifact name and you'll have similar problems.

This behavior seemed to change in Gradle 1.11+, so I think this is a bug.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:42:41 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.