How can I pass variables to Exec during execution? I want to write a pass through gradle file that will exec my current build commands which let's me move configuration from build server plans to source control managed build.gradle file. This is also part of my getting to know gradle in preparation for larger projects.
I want to have execute commands using different variables for configurations. In ant, I'd set my properties and then pass them to exec via nested env blocks. In gradle, I'm populating a map which I merge with the task's environment but this isn't working.
I can't add '<<' to the checkenv so the task code executes prior buildEnvironmentVariables being populated or is in the wrong scope. I know I'm not following proper task configuration.
Please offer suggestions or point me at the right part of the manual/docs.
build.gradle - execution gradle checkenv
def buildEnvironmentVariables = [:]
task setEnv() << {
buildEnvironmentVariables['JAVA_OPTS']="-XX:ErrorFile=foo/logs"
}
task checkenv(dependsOn: 'printEnv', type:Exec) {
workingDir '../..'
executable = 'cmd'
environment << buildEnvironmentVariables
println "buildEnvironmentVariables = " << buildEnvironmentVariables['JAVA_OPTS']
args = ['/c','set','JAVA_OPTS']
}
Should I be only adding a task to the project when it is the equivalent of a "target" and encapsulating actions like the exec within the top level tasks?
Added task is like ant target and encapsulated tasks is like ant task?
def buildEnvironmentVariables = [:]
task setEnv() << {
buildEnvironmentVariables['JAVA_OPTS']="-XX:ErrorFile=foo/logs"
}
task checkenv(dependsOn: 'printEnv') << {
println "buildEnvironmentVariables = " << buildEnvironmentVariables['JAVA_OPTS']
ext.check = exec() {
workingDir '../..'
executable = 'cmd'
environment << buildEnvironmentVariables
args = ['/c','set','JAVA_OPTS']
}
}
Thanks