Gradle add nested subproject from a multi-module project as dependency of another subproject

Assuming project sp1 and sp2 are subprojects of project p3, if you want to do:

dependencies {
    compile project(':p3:sp1')
}

Then you need to change your settings.gradle to:

rootProject.name = root

include ':p1'
include ':p2'
include ':p3'    // Keep this if this folder contains a build.gradle
include ':p3:sp1'
include ':p3:sp2'

Just to add the answer for those who might be looking, in your settings.gradle you will have

include ':p1',':p2',':p3:sp1',':p3:sp2'

if sp1 depends on sp2

then add dependency on sp1's gradle as

dependency {
   compile project(":p3:sp2")
}