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:
- 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?