I’m migrating a large project from Maven to Gradle. This project has many sub-projects with a complex directory hierarchy.
By looking at other open-source projects that use Gradle, it seems that Gradle prefers to contain all subprojects in a flat directory rather than a directory hierarchy.
Here is a brief summary of the differences of how I believe Maven and Gradle view subprojects:
- Gradle subprojects are created explicitly by the include statement in the settings.gradle file; Maven subprojects are created explicitly by the module element in the pom.xml file. * Gradle subprojects are referenced by their fully qualified name within a project hierarchy. Maven subprojects are referenced by their GAV. * A Gradle subproject’s parent is implied by its fully qualified name; A Maven subproject’s parent is explicitly declared by the parent element in the pom.xml. * A Gradle subproject’s name and root directory have a direct correlation by convention. A Maven subproject’s GAV and root directory have no correlation.
As an example:
±- app
±- business-logic
|
±- api
|
– impl
±- infrastructure
|
±- domainmodel
|
|
±- api
|
|
– impl
|
±- persistence
|
|
±- api
|
|
– impl
Needs to be referenced in the settings.gradle file this way:
include ‘app:business-logic:api’
include ‘app:business-logic:impl’
include ‘app:domainmodel:api
include ‘app:domainmodel:impl’
include ‘app:persistence:api
include ‘app:persistence:impl’
Problems arise when:
- The directory hierarchies are rather deep—the fully qualified name of subprojects becomes rather long and difficult to reference. 2. The project.name and project.projectDir have no direct correlation-- although this can be resolved by finding the project descriptor and modifying the projectDir, it is rather messy when there is no set pattern between subprojects.
Questions:
- Is the Gradle convention to have a flat directory structure for sub-projects? 2. Is there a way other than Settings.include to create project descriptors? 3. What is the best way to create a project when there is no correlation between the name and the directory? 4. What are the disadvantages to rooting all sub-projects off the rootProject? 5. What good open source examples are available that use Gradle and have a deep subproject hierarchy?