25

Assume I wanted to use Gradle with a project structure such as:

RootProject
\-- SubProjectA
    \-- SubProjectAA
    \-- SubProjectAB

How I would I achieve this?

What I tried is pretty straightforward. I've created all directories, with a structure described above:

RootProject
\-- SubProjectA
    \-- SubProjectAA
        \-- build.gradle
    \-- SubProjectAB
        \-- build.gradle
    \-- build.gradle
    \-- settings.gradle
\-- build.gradle
\-- settings.gradle

RootProject/settings.gradle:

include "SubProjectA"

RootProject/SubProjectA/settings.gradle:

include "SubProjectAA", "SubProjectAB"

There are two things I tried. First, I tried importing the project in Eclipse - which didn't detect SubProjectAA nor SubProjectAB. Stunned, I ran gradle projects in RootProject and got this output:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'RootProject'
\--- Project ':SubProjectA'

Still, thinking I made a mistake, I tried running the same command in SubProjectA, and got:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'RootProject'
\--- Project ':SubProjectAA'
\--- Project ':SubProjectAB'

I assume that resolving subprojects doesn't go recursively. Is there any workaround for this?

Every example is masked with sample names, sorry if I made any mistake.

Thanks!

Matija Folnovic
  • 906
  • 2
  • 10
  • 22

2 Answers2

31

You can only have one settings.gradle. Typically it would contain something like:

include "SubProjectA:SubProjectAA"
include "SubProjectA:SubProjectAB"

More information can be found in the "multi-project builds" chapter of the Gradle User Guide.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • 1
    Thank you for the clarification here. Do you know if there is any movement on this? I find this pretty fiddly for bigger projects. I have seen this issue but no additional comments: [link](https://github.com/gradle/gradle/issues/1559) – Maximilian Schulz Apr 16 '19 at 10:53
  • how do you write the dependency for SubProjectAA then? – Brad Mace Aug 20 '20 at 19:45
-2

try with

RootProject
\-- SubProjectA
    \-- SubProjectAA
        \-- build.gradle
    \-- SubProjectAB
        \-- build.gradle
\-- build.gradle
\-- settings.gradle

include ':SubProjectA/SubProjectAA'
Aleks G
  • 56,435
  • 29
  • 168
  • 265