# Subproject build.gradle access to root project build.gradle

**URL:** <https://discuss.gradle.org/t/subproject-build-gradle-access-to-root-project-build-gradle/21763>\
**Category:** Help/Discuss\
**Created:** [February 27, 2017, 5:08am UTC](https://discuss.gradle.org/t/subproject-build-gradle-access-to-root-project-build-gradle/21763 "2017-02-27T05:08:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phi1ipp](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@phi1ipp](https://discuss.gradle.org/u/phi1ipp)\
**Post date:** [February 27, 2017, 5:08am UTC](https://discuss.gradle.org/t/subproject-build-gradle-access-to-root-project-build-gradle/21763/1 "2017-02-27T05:08:50Z")

</div>

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"]  
}

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [February 27, 2017, 7:16am UTC](https://discuss.gradle.org/t/subproject-build-gradle-access-to-root-project-build-gradle/21763/2 "2017-02-27T07:16:54Z")

</div>

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"
```
