# Call plugin extension property becomes an assignment

**URL:** <https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909>\
**Category:** Old Forum Archive\
**Created:** [April 12, 2014, 3:40am UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909 "2014-04-12T03:40:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lzprgmr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lzprgmr/32/402_2.png) [@lzprgmr](https://discuss.gradle.org/u/lzprgmr)\
**Post date:** [April 12, 2014, 3:40am UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/1 "2014-04-12T03:40:00Z")

</div>

### Code

```gradle
class DemoExtension {
    String non_closure
    def override_closure = {}
}
  class DemoPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.extensions.create('demoExtension', DemoExtension)
    }
}
  apply plugin: DemoPlugin
demoExtension {
    non_closure = "Hello"
    override_closure= {String jniPaths -> return ""}
    new_closure = {}
}
println "Non Closure:"
println demoExtension.non_closure
demoExtension.non_closure("hello, world")
println demoExtension.non_closure
  println "Override closure:"
println demoExtension.override_closure
demoExtension.override_closure("hello, world")
println demoExtension.override_closure
  println "New closure:"
println demoExtension.new_closure
demoExtension.new_closure("hello, world")
println demoExtension.new_closure

```

## Output

```gradle
Non Closure:
Hello
hello, world
Override closure:
build_7rtsbsk9dvhokdfj78dc5gki0k$_run_closure5_closure13@6cf26de4
hello, world
New closure:
build_7rtsbsk9dvhokdfj78dc5gki0k$_run_closure5_closure14@4aff7dfe
build_7rtsbsk9dvhokdfj78dc5gki0k$_run_closure5_closure14@4aff7dfe

```

## Question: If a closure defined in the plugin extension, when I try to call it, it is actually an assignment statement, which set my closure to a weird value (which takes 0.5 day to diagnose), but if the closure is not predefined in the extension, it is actually calling the closure. Why would we want to support a function call like assignment in this case, is there a way to disable it?

Thanks.

---

<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:** [April 12, 2014, 1:42pm UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/2 "2014-04-12T13:42:00Z")

</div>

It’s a known limitation. A safe way to call the closure (which presumably will be done by a (script) plugin) is ‘closure.call(arg)’.

---

<div class="post-metadata">

**Author:** ![lzprgmr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lzprgmr/32/402_2.png) [@lzprgmr](https://discuss.gradle.org/u/lzprgmr)\
**Post date:** [April 13, 2014, 1:38pm UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/3 "2014-04-13T13:38:00Z")

</div>

Thanks Peter, the behavior seems quite weird to me, when are we going to fix this?

---

<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:** [April 13, 2014, 1:42pm UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/4 "2014-04-13T13:42:00Z")

</div>

It’s a consequence of the feature that ‘=’ can be omitted when setting a property.

---

<div class="post-metadata">

**Author:** ![lzprgmr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lzprgmr/32/402_2.png) [@lzprgmr](https://discuss.gradle.org/u/lzprgmr)\
**Post date:** [April 13, 2014, 1:44pm UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/5 "2014-04-13T13:44:00Z")

</div>

But if you look at the example above, new\_closure = {} actually doesn’t have this problem, so is this a groovy limitation or gradle extension limitation?

---

<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:** [April 13, 2014, 1:46pm UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/6 "2014-04-13T13:46:00Z")

</div>

It’s a feature of enhanced Gradle objects such as extensions, and hence also a limitation of them (when used with closures).

---

<div class="post-metadata">

**Author:** ![lzprgmr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lzprgmr/32/402_2.png) [@lzprgmr](https://discuss.gradle.org/u/lzprgmr)\
**Post date:** [April 14, 2014, 1:15am UTC](https://discuss.gradle.org/t/call-plugin-extension-property-becomes-an-assignment/6909/7 "2014-04-14T01:15:00Z")

</div>

Well, it seems this feature doesn’t provide much benefit, while is very easy to cause hard-to-identify problems, have you guys even consider to deprecate it?
