Get project dependencies when using composite builds

I’m currently trying to migrate a project to using composite builds. But when migrating one a custom plugin, I ran into an issue I can currently only solve by using internal gradle API.

The setup is something like this (simplified):

  • Build 1
    • Project 1
    • Project 2, depends on Project 1
  • Build 2, includes build 1
    • Project 3, depends on Project 2

The custom plugin must for Project 3 retrieve all referenced projects (so in the code below the projects array should contain both Project 1 and Project 2).

The current solution using internal API:s looks like this:

def projects = [];
// Get all dependencies
project.getConfigurations().getByName("runtime").getIncoming().getResolutionResult().getAllDependencies().each {
    // Only interested in resolved dependencies
    if(it instanceof ResolvedDependencyResult) {
        ResolvedDependencyResult resolvedResult = (ResolvedDependencyResult)it;

        // Check if it's a project dependency
        if( instanceof ProjectComponentIdentifier) {
            ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier);
            // Check if it is part of current build or included build
            if(! {
                // Retreive included project from other build, using internal API
                def dependentProject = ((IncludedBuildInternal)project.gradle.includedBuild(;
            } else {
// Remove duplicates
return projects.unique();

So, what I’m looking for is essentially a replacement for the line

def dependentProject = ((IncludedBuildInternal)project.gradle.includedBuild(;

For retrieving tasks I know I can do


But I can’t find an equivalent for projects.