Gradle composite builds - can you have a dependency to a java sub-project from an included multi-project build?

Let’s say you have 2 gradle projects. The first is a multi project with 2 java sub-projects:

rootProject
    :my:subProject1
    :myother:subProject2

The second gradle project is a single project that includeBuild’s the root project:

secondProject
    includeBuild '../rootProject'

I want to make a compile dependency of :my:subProject1 into secondProject.

So basically I want to add the following to secondProject’s build.gradle file:

dependency {
    compile(project(':my:subProject1')) 
}

When I try to do that, it returns error: Project with path ‘:my:subProject1’ could not be found in root project ‘secondProject’

I seems like I can only resolve the dependency when I do the dependency as group:artifact:version. For example: my.root.project:subProject1:1.0.0. But why would it make me do that? Why not let me access the composite build’s project hierarchy?

Have you tried dependencySubstitution?

in settings.gradle use something like that:

includeBuild('../rootProject') {
    dependencySubstitution {
        substitute module('my.root.project:subProject1') with project(':')
    }
}

read this for details

I haven’t tried this but did you try referencing subProject1 via rootProject, in your dependency? So something like rootProject:subProject1.