Is their a way I can access a variable declared and defined inside buildSrc/build.gradle in buildSrc/settings.gradle?
That’s hardly possible, as the settings script is executed before the project script, unless you register a lazy action that is evaluated at build script evaluation time.
If it is a hard-coded value you could also move it to gradle.properties
where it properly belongs anyway in that case, then you can access it from the settings script and the build script.
But maybe you might want to elaborate on the use-case, maybe there is some better advice if you share more information about what you try to achieve.
In this scenario I am loading credentials to connect artifactory in buildSrc/build.gradle and credentials are defined in local.properties. The reason I am keeping it out of gradle.properties is because I do not want to check-in these properties in code repository.
I want to use these credentials again in buildSrc/settings.gradle without have to re-load it from local.properties, hence wanted to see if there is a way to re-use/ share variables between these 2 files.
If at all, then the other way around.
But it would probably be better to just configure your repositories in the settings script, then you shouldn’t need the credentials in the build script.
Or you put the credentials in <GRADLE_USER_HOME>/gradle.properties
, then they are also not checked in but available to both, the settings script and the build script and you could even use the built-in credentials handling.
Thanks much, that works.