Skip to content

Instantly share code, notes, and snippets.

@musketyr
Created April 1, 2011 20:49
Show Gist options
  • Save musketyr/898832 to your computer and use it in GitHub Desktop.
Save musketyr/898832 to your computer and use it in GitHub Desktop.
How could be simply passed arguments to the Gradle build
task args
args.map = [:]
tasks.addRule("Pattern: <property>=<value>: Passes arguments to the scripts") { String taskName ->
def match = taskName =~ /(.*?)=(.*?$)/
if(match){
args.map[match[0][1]] = match[0][2]
task(taskName) << {
println "Used to pass value ${match[0][2]} to args.map.${match[0][1]}"
}
}
}
task testaArgs(dependsOn: args) << {
if(args.map){
println "Arguments passed:"
args.map.each{ property, value ->
println "\t $property=$value"
}
} else {
println "No arguments passed!"
}
if(args.map.plugin){
println "Plugin: $args.map.plugin"
} else {
println 'No plugin selected'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment