Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 911
Javier Villa Avatar asked Dec 14 '22 19:12

Javier Villa


1 Answers

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).

like image 184
Peter Niederwieser Avatar answered Apr 17 '23 00:04

Peter Niederwieser