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(resolvedResult.selected.id instanceof ProjectComponentIdentifier) {
ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)resolvedResult.selected.id;
// Check if it is part of current build or included build
if(!projectComponentIdentifier.build.isCurrentBuild()) {
// Retreive included project from other build, using internal API
def dependentProject = ((IncludedBuildInternal)project.gradle.includedBuild(projectComponentIdentifier.build.name)).configuredBuild.getRootProject().project(projectComponentIdentifier.projectPath);
projects.add(dependentProject);
} else {
projects.add(project.project(projectComponentIdentifier.projectPath));
}
}
}
}
// Remove duplicates
return projects.unique();
So, what I’m looking for is essentially a replacement for the line
def dependentProject = ((IncludedBuildInternal)project.gradle.includedBuild(projectComponentIdentifier.build.name)).configuredBuild.getRootProject().project(projectComponentIdentifier.projectPath);
For retrieving tasks I know I can do
project.gradle.includedBuild(projectComponentIdentifier.build.name).task('taskName')
But I can’t find an equivalent for projects.