How can reuse a common function in a subproject?


(Jay Vyas) #1

As mentioned in this post http://comments.gmane.org/gmane.comp.programming.tools.gradle.user/3542

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

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,


#2

The simplest way is probably:

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

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