How can I make compilerConstans in this example to be visible for compile task? Whatever I do, compilerConstants is empty inside compile task but works just fine in foo task. Basically I need to be able to select those parameters from command line for different build targets.
Or maybe there’s some completely different, better way of doing this?
Note that this is heavily simplified version of my real problem and I really wouldn’t like to have three (desktop, mobile, web) almost identical 20-line compile tasks which differ only by compilerConstants.
String AIR_HOME = System.getenv('FLEX_HOME')
def compilerConstants = []
task setupDesktop << {
compilerConstants.push('-define=BUILD::desktop,true')
}
task setupMobile << {
compilerConstants.push('-define=BUILD::desktop,false')
}
task compile (type: JavaExec) {
main = "com.adobe.flash.compiler.clients.MXMLC"
classpath = files("${AIR_HOME}/lib/compiler.jar")
def argsList = []
// compiler constants
argsList = (argsList << compilerConstants).flatten()
println 'compile args: ' + argsList
args = argsList
}
task foo << {
def argsList = []
argsList = (argsList << compilerConstants).flatten()
println 'foo args: ' + argsList
}