# Property and hasProperty do not seem to be consistent with each other

**URL:** <https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114>\
**Category:** Old Forum Archive\
**Created:** [February 3, 2012, 4:04pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114 "2012-02-03T16:04:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [February 3, 2012, 4:04pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/1 "2012-02-03T16:04:00Z")

</div>

As part of the my Gradle build running on TeamCity, the following code is executed:

```gradle
allprojects {
      println property('teamcity')
    println hasProperty('teamcity')
  }

```

Interestingly, the first line returns a map with many values, and the second line returns false. That seems inconsistent to me.

---

<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:** [February 3, 2012, 4:32pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/2 "2012-02-03T16:32:00Z")

</div>

Which Gradle version? Can you try:

```gradle
allprojects { prj ->
    println prj.property('teamcity')
    println prj.hasProperty('teamcity')
}

```

The implementations of the two methods look consistent to me.

---

<div class="post-metadata">

**Author:** ![Spencer\_Allain](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Spencer\_Allain](https://discuss.gradle.org/u/Spencer_Allain)\
**Post date:** [February 3, 2012, 6:34pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/3 "2012-02-03T18:34:00Z")

</div>

Although I no longer see a link from [gradle.org](http://gradle.org) to the JIRA issues tracker, there is a thread where Peter explains in more detail exactly why they differ without explicitly binding a named variable to the project object.

[http://issues.gradle.org/browse/GRADLE-1826](http://issues.gradle.org/browse/GRADLE-1826)

-Spencer

---

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [February 6, 2012, 12:54pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/4 "2012-02-06T12:54:00Z")

</div>

Hi Peter

It works properly when using your suggested code.

It seems things behave differently between using an explicit project closure parameter and none.

Regards, Etienne

---

<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:** [February 6, 2012, 8:46pm UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/5 "2012-02-06T20:46:00Z")

</div>

It’s likely a conflict between ‘Project.hasProperty()’ and ‘Object.hasProperty()’. The latter is added by Groovy. We should do some research whether this is something we can fix on our side.

---

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [February 7, 2012, 7:25am UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/6 "2012-02-07T07:25:00Z")

</div>

Got it. It seems that it is safer to always use an explicit closure parameter.

---

<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:** [February 7, 2012, 11:25am UTC](https://discuss.gradle.org/t/property-and-hasproperty-do-not-seem-to-be-consistent-with-each-other/2114/7 "2012-02-07T11:25:00Z")

</div>

Safer yes, but it’s a rare issue and I haven’t seen it for anything other than ‘hasProperty’. Hence I almost never use an explicit parameter.
