my goal have common class other build files can see in gradle. have created folder called buildsrc , in root directory of android project. contents this:
class countryflavors { def closure getflavor() { return callback; } closure callback ={ mock { applicationid "ca.mysite.mock" } prod { applicationid "ca.mysite.prod" } } } from documentation states class put folder buildsrc automatically put in same classpath build script android. instead whats happening class cannot found. tried reference class in build.gradle file on app level cant find class. here how calling class countryflavors:
new countryflavors().getflavor() the compiler compains class cannot found. class file in buildsrc , named "build.gradle". blanked out root folder in photo proprietary reasons. missing ?
my end goal have class defined externally can return closure me can use in build script. @opal
try on putting countryflavor class in:
buildsrc/src/main/groovy/countryflavor.groovy https://docs.gradle.org/current/userguide/custom_tasks.html
to answer question created simple project. simplified structure (i cut of .gradle, gradle wrapper etc):
c:. | build.gradle | settings.gradle | +---buildsrc | | | \---src | \---main | \---groovy | countryflavors.groovy build.gradle simply:
task mytask << { println new countryflavors().getflavor() } i put getflavor() method:
println "this callback" output is:
gradle -q mytask callback countryflavors$_closure1@3ce443f9
Comments
Post a Comment