Vas Vas - 1 year ago 97
Groovy Question

Keep defs in a separate file

I have several defs in my main build.gradle file. Is it possible to move them into a separate file, and then just reference them?
Something like this (don't mind the syntax):


def foo = "foo"
def bar = "bar"
def baz = "baz"


println $foo
println $bar
println $baz

Vas Vas
Answer Source

Finally figured it out.

In foobar.gradle, set up the defs like this: = "foo" = "bar"
ext.baz = "baz"

Then in main.gradle, make sure to include this line:

apply from: 'foobar.gradle'

Now variables can be used as freely as if they are part of the main.gradle file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download