How can I reuse a method which is declared in an other script?


(fabien perie) #1

How can I reuse a method which is declared in an other gradle script ? With the expression « apply from: “.gradle” », the script doesn’t work because the method is not found. An idea ? Thanks a lot. F.


(Peter Niederwieser) #2

You can use a standard Groovy trick:

script.gradle

hello = { String name -> println "Hello $name" }

build.gradle

apply from: "script.gradle"
  hello("fred")

(dusiabh) #3

can you give example for eliminate following warning?

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. … >Deprecated dynamic property: “hello”

How I can pass more then one parameters?


(dusiabh) #4

For eliminate the warning, “ext” namespace should be added:

script.gradle

ext.hello = { String name -> println "Hello $name" }