Empty directory grouping subprojects


I’m not sure how to configure the settings.gradle for a build structure something like this:

├── build.gradle
├── group1
│ ├── project3
│ │ └── build.gradle
│ └── project4
│ └── build.gradle
├── project1
│ └── build.gradle
├── project2
│ └── build.gradle
└── settings.gradle

  • The group1 directory is an empty directory.
  • The projects under group1 all depend on project1 and project2.

Based on some googling my understanding is that there should be a single settings.gradle. I tried something like this:

include “:project1”
include “:project2”
include “:group1:project3”
include “:group1:project4”

And in the build.gradle for project3 and project4:

apply from: “$rootProject.projectDir/src-utils/jar.gradle”

dependencies {
compile project(‘:project1’)
compile project(‘:project2’)

Is it ok to have an empty directory in a gradle build?
How to you reference the subproject it contains in the top level settings.gradle?
Would the $rootProject.projectDir correctly reference the top level directory (not the empty directory) when used in the subproject build.gradle?

I have found similar questions but most are related to applying configuration to sub projects and I have been unable to figure out the correct configuration.

Any help would be much appreciated.



I have changed the top level settings.gradle to be like this:

include “:group1/project3”

That seems to work. What I’m nor sure about is why exactly it is working! How does project3 determine what the rootProject is? How does it know that it is not the root project?

Also, it would be an added bonus if I could run ‘gradle commands’ from the empty directory to build all the subprojects but I have not figured out how to do that (I can run gradle commands from the top level or the subproject itself).

Thanks to an answer to a different question I think this has been answered. See the other question: