I have created a settings.gradle that searches an arbitrary directory tree for any Gradle projects and adds them as subprojects:
def searchRoot = rootDir.toPath().resolve(getProperty("searchRoot")).normalize().toAbsolutePath();
Files.walkFileTree(searchRoot, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (file.getFileName().toString().equals("build.gradle")) {
String projectName = ":" + searchRoot.relativize(file.getParent()).toString().replaceAll("/", ":").replaceAll("\\\\", ":");
include projectName;
project(projectName).projectDir = file.getParent().toFile()
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
if (dir.equals(rootDir.toPath())) {
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
}
});
This works fine, except that one of the projects that I am importing has two subprojects, one of which has a project dependency on the other, e.g. the build.gradle for subproject A has the following in its dependencies section:
runtimeOnly(project(path: ":project B", configuration: 'confName'))
Because the subprojects have been dynamically included, the project path is now wrong.
So, I am wondering if there is anything I can put in the settings.gradle that will allow me to intercept that dependency and replace the project path with the correct one? I’ve tried putting in a dependencyResolutionManagement section, but that doesn’t appear to be being called.
Thanks,
Carl