# How can reuse a common function in a subproject?

**URL:** <https://discuss.gradle.org/t/how-can-reuse-a-common-function-in-a-subproject/4036>\
**Category:** Old Forum Archive\
**Created:** [July 26, 2014, 2:42am UTC](https://discuss.gradle.org/t/how-can-reuse-a-common-function-in-a-subproject/4036 "2014-07-26T02:42:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayunit100](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jayunit100/32/618_2.png) [@jayunit100](https://discuss.gradle.org/u/jayunit100)\
**Post date:** [July 26, 2014, 2:42am UTC](https://discuss.gradle.org/t/how-can-reuse-a-common-function-in-a-subproject/4036/1 "2014-07-26T02:42:00Z")

</div>

As mentioned in this post [http://comments.gmane.org/gmane.comp.programming.tools.gradle.user/3542](http://comments.gmane.org/gmane.comp.programming.tools.gradle.user/3542)…

I’ve attempted to inject a method into my subprojects like so:

```gradle
subprojects{
   runme = { print("hi") }
 }

```

However, in the super project, at this exact line, i get a build error “runme not defined”)

The exact error i get: ‘’’ \> No such property: runme for class: org.gradle.api.internal.project.DefaultProject\_Decorated

‘’’

So, how can I use the subprojects directive in my root project… to define/inject method from the root project from a subproject,

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [July 26, 2014, 2:49am UTC](https://discuss.gradle.org/t/how-can-reuse-a-common-function-in-a-subproject/4036/2 "2014-07-26T02:49:00Z")

</div>

The simplest way is probably:

```gradle
subprojects{
   ext.runme = { print("hi") }
 }

```

This defines ‘runme’ as an ‘extraProperty’ on the project.
