https://stackoverflow.com/a/23689696/1757491
我从上面的答案开始从提议的解决方案中使用一些信息:应用程序插件方法
(build.gradle)
apply plugin: 'application'
mainClassName = "com.mycompany.MyMain"
run {
/* Need to split the space-delimited value in the exec.args */
args System.getProperty("exec.args").split()
}
命令行:
gradle run -Dexec.args="arg1 arg2 arg3"
它可以很好地达到预期的目的,但似乎有副作用。传递命令行参数以进行运行很有意义,但是我必须为每个任务传递它们,例如:
gradle tasks -Dexec.args="arg1 arg2 arg3"
如果我忽略了
-Dexec.args="arg1 arg2 arg3"
我懂了
"build failed with an exception"
Where:path\build.gradle line:18 which if where my run{ } is.
您可以通过两种不同的方法解决它:
首先:
exec.args
属性可以直接在主类中读取-因此根本不需要args
在run
闭包中进行配置。
第二:
只是如果它:
execArgs = System.getProperty('exec.args')
if(execArgs)
args = execArgs.split()
由问题提问者(Question Asker)编辑:使用if确实可行,但是我不得不稍微更改语法。
if(System.getProperty("exec.args") != null) {
args System.getProperty("exec.args").split()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句