Access local.properties from settings.gradle for composite builds

Hello!

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 local.properties 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 local.properties 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("local.properties").exists()) {
    properties.load(rootProject.file("local.properties").newDataInputStream())
}

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

Thanks!

Just remove rootProject. and you should probably be fine.

1 Like

thank you this was exactly it