Multiproject within a multiproject

I’m in the beginnings of converting a large baseline from ‘ant’ to ‘gradle’. I’d like to avoid restructuring as much as possible and have run into a snag with what I would call a multiproject within a multiproject. Assume I have the following:


  • ProjectB
  • ProjectC
    | - ProjectD
    | - ProjectE

ProjectA - settings.gradle contains: include(‘ProjectB’, ‘ProjectC’)
ProjectC - settings.gradle contains: include(‘ProjectD’, "ProjectE’)

Sitting in ProjectA; ./gradlew build

Expectation: build ProjectB, then traverse ProjectC and build ProjectD and ProjectE
Result: only ProjectB is actually built

If I manually change directory to ProjectC and ./gradlew build, ProjectD and ProjectE build

What am I doing wrong? ProjectC is just the example created from running ‘gradle init’ and selecting options for a Java multiproject.

Sitting in ProjectA; ./gradlew tasks --all

Other tasks reports ProjectB:compileJava, but there is no ProjectC:compileJava or whatever task would traverse into ProjectD and ProjectE.

I found my own solution…

Not sure about the claim that there should only be one settings.gradle file, but the solution was to ensure ProjectA/settings.gradle had include(‘ProjectB’, ‘ProjectC:ProjectD’, ‘ProjectC:ProjectE’). Maybe there is a better solution, but this is a reasonable workaround.

You can either have one big multi-project build with what you showed in your last post and only the one settings script in the root project.
Alternatively you could make ProjectC with subprojects ProjectD and ProjectE an own “stand-alone” build with own settings script, that you then include as sub build instead of sub project in ProjectA.
That’s called composite build if you want to further read up on it and would then be includeBuild instead of include.
Which you use in your situation is more a question of taste or isolation or organisation, both would work if you do it properly.