gradle:应用程序运行args无法传递系统属性

时间:2019-05-28 20:55:02

标签: gradle

5.4.1级

apply plugin: application

run {
   main = "mypackage.Foo"
}

运行:

gradlew run --args="-Dfoo=bar -Dhello=world"

在运行应用程序时尝试使用--args传递系统属性。但是没有设置。

2 个答案:

答案 0 :(得分:0)

gradlew -Dfoo=bar -Dhello=world run --args="arg1"

--args是传递给main方法的内容。

答案 1 :(得分:0)

您将需要从CLI中将系统属性显式复制到相应的run命令/插件系统属性中,这很不幸:

// The run task added by the application plugin is also of type JavaExec.
tasks.withType(JavaExec) {
    // Assign all Java system properties from the command line to the JavaExec task.
    systemProperties System.properties
}