Search code examples
gradlesettingsproject

Getting settings object from the buildscript


I am trying to access the settings object from the root project's build script.

The reason is I want to define a list in the settings.gradle file which will be a list of subprojects, kind of:

settings.gradle

projectNames = ['prjA', 'prjB']

Would like to do something like:

build.gradle (root project)

projectNames = settings.projectNames
// Use projectName in tasks

And then access it in build.gradle for various tasks, such as resolving those names into URLs to git-clone them. However I can't seem to find a way to declare some arbitrary groovy object which is visible between these two scripts. Note I may potentially like that list to be related but not equal to the project names. I guess the question sums up to sharing POGOs between those two files and accessing the settings object.

I'm pretty new to Gradle.


Solution

  • There isn't a way to get to the settings object from a build script. However, both scripts share a gradle object, which you could use to set an extra property in the settings script (e.g. gradle.ext.foo = "bar"), and read it in the build script (e.g. println gradle.foo).