Subproject build.gradle access to root project build.gradle

I have a root project build.gradle with a block

subprojects { def loginconfig = "$home/conf/login.conf" }
In one of my sub-projects I want to have its own build.gradle where to use loginconfig defined in root build.gradle. Is it possible to achieve? Something like the following in subproject build.gradle

apply plugin: ‘application’

run {
args = ["-loginconf=$loginconfig"]

You don’t want to declare loginconfig as a variable in your root project. The variable is only accessible in the scope it was declared. Therefore, it’s only available in the subprojects { } block, not to the actual subprojects.

If you wish to set a value from the root project that can only be used in the subprojects, you can set loginconfig as an extra property on just the subprojects:

subprojects {
    ext.loginconfig = "$home/conf/login.conf"

or you can set it on the root project (unless there’s a good reason to not have it there) and it will automatically be inherited by the subprojects:

ext.loginconfig = "$home/conf/login.conf"