Access from settings.gradle for composite builds


I am looking for some help/feedback on how to allow a user to configure their own paths for projects used in a composite build.

Currently our composite build script uses this function defined in settings.gradle

def addComposite(String projectName, Action<ConfigurableIncludedBuild> action) {
        if (script.file("${script.rootDir}/../$projectName").exists() && this.compositeBuildsFlags[projectName]) {
            script.includeBuild("${script.rootDir}/../$projectName", action)

However, this requires that the user maintain all desired projects necessary to make a composite build in the same root directory.

Ideally one could define project paths in and access those in the settings.gradle file to avoid needing to maintain a strict hierarchy and clutter the project root directory. This becomes especially useful in larger projects that have many modules.

Most of the articles and solutions elsewhere include snippets which let you access within the build.gradle file, but not much is mentioned about settings.gradle.

The following will not build if included in settings.gradle

if (rootProject.file("").exists()) {

How can you access from the settings.gradle file in order to load values from it?


Just remove rootProject. and you should probably be fine.

1 Like

thank you this was exactly it