Reputation: 62519
I have a closure of defined in a another build.gradle file called other.gradle. Here is the contents:
Closure callback = {
productFlavors {
...
devel {
...
}
prod {
...
}
}
}
Now in my build.gradle file I want to call this closure like this:
apply from: 'other.gradle'
productFlavors(callback());
but I keep getting an error that callback() cant be found. Both files are in the same directory. My issue is how do i get the build.gradle file to see the callback closure in the 'other.gradle' file.
Upvotes: 0
Views: 1348
Reputation: 84784
It should be done in the following way:
other.gradle
project.ext.callback = { c ->
println(c)
}
build.gradle
apply from: 'other.gradle'
callback('a')
Or in same cases callback
should be referred via project.instance
, e.g. project.callback('a')
.
Upvotes: 2