How can reuse a common function in a subproject?

As mentioned in this post

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

   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,

The simplest way is probably:

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

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

1 Like