# Settings.properties define variable use in root project of multiproject

**URL:** https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852
**Category:** Old Forum Archive
**Created:** [June 10, 2013, 9:23am UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852 "2013-06-10T09:23:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zdenek](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zdenek](https://discuss.gradle.org/u/zdenek)
#### Post date: [June 10, 2013, 9:23am UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/1 "2013-06-10T09:23:00Z")

</div>

Hi,

Is it possible to create variable/property in settings.properties and use it in multiproject root project tasks?

I need bootstrap task to checkout project structure from cvs (20 - 25 cvs modules).

Currently I have settings.propertis with project includes + some logic not to include optional projects:

```gradle
def addOptionalProject(String projectDir){
      if (file(projectDir).exists()){
        include projectDir
        println "Optional project added. Project ${projectDir}"
    }
}

```

I would like to be able to checkout all cvs modules/sub-projects.

I need checkout projects which are optional and are not included in actual sub-projects list and I thought best way would be create list of project names in settings.properties and use it in custom task to perform cvs checkout and in loop in settings.properties to include projects while building after checkout.

Is it possible? Do you think there is better way to avoid duplicate project definition in settings.properties and in my task/plugin configuration in build.gradle?

Thanks.

Regards, Zdenek

---

<div class="post-metadata">

### Author: ![zdenek](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zdenek](https://discuss.gradle.org/u/zdenek)
#### Post date: [December 9, 2013, 4:35pm UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/2 "2013-12-09T16:35:00Z")

</div>

no need for cvs more.

I use custom gradle config file to define projects and its types, this is used in settings.gradle and in the installer to generate dependencies during config phase.

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [December 9, 2013, 4:53pm UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/3 "2013-12-09T16:53:00Z")

</div>

One way to get information across is via an extra property on the ‘gradle’ object.

settings.gradle

```gradle
gradle.ext.foo = "bar"

```

build.gradle

```gradle
println gradle.foo

```

---

<div class="post-metadata">

### Author: ![Mickelback](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mickelback/32/1128_2.png) [@Mickelback](https://discuss.gradle.org/u/Mickelback)
#### Post date: [December 24, 2013, 9:32pm UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/4 "2013-12-24T21:32:00Z")

</div>

If setting a value on the extra property of the gradle object, does it always have to be referenced via “gradle.foo” from within the build.gradle as well?

Is there a way to set the property in the settings.gradle file so that from within any project in a multi-project build, the said property could simply be referenced from either “project.foo”, or even just “foo”?

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [December 25, 2013, 6:40am UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/5 "2013-12-25T06:40:00Z")

</div>

Try ‘gradle.rootProject.ext.foo = “bar”’. Then you should be able to refer to the property as ‘foo’ from anywhere.

---

<div class="post-metadata">

### Author: ![Mickelback](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mickelback/32/1128_2.png) [@Mickelback](https://discuss.gradle.org/u/Mickelback)
#### Post date: [January 6, 2014, 5:20pm UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/6 "2014-01-06T17:20:00Z")

</div>

Thanks Peter for your help with this. For what it is worth, when attempting what you suggested resulted in the following:

[http://forums.gradle.org/gradle/topics/java\_lang\_illegalstateexception\_the\_root\_project\_is\_not\_yet\_available\_for\_build](http://forums.gradle.org/gradle/topics/java_lang_illegalstateexception_the_root_project_is_not_yet_available_for_build)

This was using Gradle v1.10. Don’t know if this if a bug or what, but wanted to let you know.

Thanks again!

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [January 6, 2014, 5:34pm UTC](https://discuss.gradle.org/t/settings-properties-define-variable-use-in-root-project-of-multiproject/6852/7 "2014-01-06T17:34:00Z")

</div>

I don’t think it’s a bug. ‘gradle.ext.foo = “foo”’ and ‘println foo’ seems like the correct solution.
