如何将参数从 gradle exec 任务传递到命令行
How to pass argument from gradle exec task to commandline
我正在尝试将 bat 和 sh 文件(取决于 OS 处于 运行 状态)与 gradle exec 任务挂钩。但是我无法弄清楚如何从 exec 任务向 bat/sh 发送参数。
task testing(type:Exec) {
workingDir '.'
if (System.properties['os.name'].toLowerCase().contains('windows')) {
if ( project.hasProperty("arg1") ) {
println arg1
args arg1
commandLine 'cmd', '/c', 'run.bat'
}else{
commandLine 'cmd', '/c', 'run.bat'
}
}else {
if ( project.hasProperty("arg1") ) {
args arg1
commandLine './run.sh'
}else{
commandLine './run.sh'
}
}
}
如果我 运行 此任务为:gradle testing -Parg1=test
,在 println arg1
中,它会打印 test
但是我如何将此测试作为参数传递给 bat/sh 文件。
通过 commandLine
传递 arg
Windows
commandLine 'cmd', '/c', 'run.bat' ,arg1
Linux / mac
commandLine './run.sh' , arg1
我正在尝试将 bat 和 sh 文件(取决于 OS 处于 运行 状态)与 gradle exec 任务挂钩。但是我无法弄清楚如何从 exec 任务向 bat/sh 发送参数。
task testing(type:Exec) {
workingDir '.'
if (System.properties['os.name'].toLowerCase().contains('windows')) {
if ( project.hasProperty("arg1") ) {
println arg1
args arg1
commandLine 'cmd', '/c', 'run.bat'
}else{
commandLine 'cmd', '/c', 'run.bat'
}
}else {
if ( project.hasProperty("arg1") ) {
args arg1
commandLine './run.sh'
}else{
commandLine './run.sh'
}
}
}
如果我 运行 此任务为:gradle testing -Parg1=test
,在 println arg1
中,它会打印 test
但是我如何将此测试作为参数传递给 bat/sh 文件。
通过 commandLine
Windows
commandLine 'cmd', '/c', 'run.bat' ,arg1
Linux / mac
commandLine './run.sh' , arg1