# Project.property(name) does not take value from 'ancestor'

**URL:** <https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041>\
**Category:** Bugs\
**Created:** [January 30, 2016, 1:50pm UTC](https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041 "2016-01-30T13:50:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xtracoder](https://avatars.discourse-cdn.com/v4/letter/x/45deac/32.png) [@xtracoder](https://discuss.gradle.org/u/xtracoder)\
**Post date:** [January 30, 2016, 1:50pm UTC](https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041/1 "2016-01-30T13:50:47Z")

</div>

Either I do not correctly understand what is the ‘ancestor’ projects in terms of Gradle or `project.property(name)` does not work according to spec of [project.property(name)](https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#property(java.lang.String)):

> 6 . Search up through this project’s ancestor projects for a convention property or extra property with the given name.

In the test project (`child-l1:child-l2`) below I expect this to be printed (because values are redefined in the immediate parent project `child-l1`):

```
version = '1.2.3(child-l1)'
extProp = 'extProp-ValueFromChildL1'
extProp1 = 'extProp-ValueFromChildL1'

```

but I’m getting following (values are taken from root `gradle.properties`)

```
version = 1.2.3(gradle.properties)
extProp = extProp-ValueFromGradleProperties
extProp1 = extProp1-ValueFromGradleProperties

```

Test project is attached and its files are provided below. For the test, i’m running

```
gradle none

```

in the folder `./child-l1/child-l2`. Gradle version is `1.10`

* * *

`settings.gradle`

```
println 'Evaluating settings'

rootProject.name = 'test'

include 'child-l1'
include 'child-l1:child-l2'

```

`gradle.properties`

```
#org.gradle.configureondemand=false
version=1.2.3(gradle.properties)
extProp=extProp-ValueFromGradleProperties
extProp1=extProp1-ValueFromGradleProperties

```

`build.gradle`

```
println 'Evaluating root'

project.version='1.2.3(root)'
project.ext.extProp = 'extProp-ValueFromRoot'
project.metaClass.extProp1 = 'extProp-ValueFromRoot'

```

`./child-l1/build.gradle `

```
println 'Evaluating child-l1'

project.version='1.2.3(child-l1)'
project.ext.extProp = 'extProp-ValueFromChildL1'
project.metaClass.extProp1 = 'extProp-ValueFromChildL1'

```

`./child-l1/child-l2/build.gradle `

```
println 'Evaluating child-l2'

println 'version=' + project.version
println 'extProp=' + project.property('extProp')
println 'extProp1=' + project.property('extProp1')

println 'extProp(parent)=' + project.parent.property('extProp')

task none {}

```

[test-project.zip](https://discuss.gradle.org/uploads/short-url/J0jdBx6CWCKJQTCLfn2YaHvUiU.zip) (1.5 KB)

---

<div class="post-metadata">

**Author:** ![xtracoder](https://avatars.discourse-cdn.com/v4/letter/x/45deac/32.png) [@xtracoder](https://discuss.gradle.org/u/xtracoder)\
**Post date:** [January 30, 2016, 2:56pm UTC](https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041/2 "2016-01-30T14:56:51Z")

</div>

I’ve got why it is working this way - it appears that values from root ‘gradle.properties’ are fed into `project.ext` of every sub-module before evaluation. This way - property will be available immediately in each project, but it will not be possible to redefine value in parent for child projects.

I guess it would be better to feed ‘gradle.properties’ only into ‘rootProject.ext’. Child projects should lookup value in parents and have ability to (optionally) redefine value for self and child projects.

---

<div class="post-metadata">

**Author:** ![xtracoder](https://avatars.discourse-cdn.com/v4/letter/x/45deac/32.png) [@xtracoder](https://discuss.gradle.org/u/xtracoder)\
**Post date:** [January 30, 2016, 3:58pm UTC](https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041/3 "2016-01-30T15:58:09Z")

</div>

I’ve tried to workaround the problem by moving ‘non-global’ properties from `gradle.properties` into root `build.gradle`. Apart from being non-natural to define build properties explicitly in `build.gradle`, it also just does not work reliably:

- `project.version` is nor inherited to children and nor evaluated from ancestors - thus always `undefined`
- with `org.gradle.configureondemand=true` intermediate parent project is not evaluated and therefore behavior is different:

when

- `configureondemand=true` - output is `extProp=extProp-ValueFromRoot`
- `configureondemand=false` - output is `extProp=extProp-ValueFromChildL1`

So … it seems there is no reliable workaround for that problem.

---

<div class="post-metadata">

**Author:** ![xtracoder](https://avatars.discourse-cdn.com/v4/letter/x/45deac/32.png) [@xtracoder](https://discuss.gradle.org/u/xtracoder)\
**Post date:** [January 30, 2016, 5:41pm UTC](https://discuss.gradle.org/t/project-property-name-does-not-take-value-from-ancestor/14041/4 "2016-01-30T17:41:14Z")

</div>

Regarding inheritance of project version into children - it may be not applicable to most of projects, but in my case each sub-tree of sub-modules has own version and I’d like to set it once in the sub-tree root for all its children.
