将 jvm 参数传递给 Gradle 测试任务

Sof*_*ker 5 java cucumber gradle

我想将 JVM 参数传递给我的 Gradle 测试任务。我使用 Cucumber 功能文件中的参数:${app.url}. 在build.gradle文件中,我放置了这些行:

test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}
Run Code Online (Sandbox Code Playgroud)

当我执行时gradle test -Dapp.url=http://.....,我没有看到参数已传递给应用程序。我也尝试了以下方法,但结果是相同的:

test {
    testLogging.showStandardStreams = true
    systemProperty "app.url", System.getProperty("app.url")
}
Run Code Online (Sandbox Code Playgroud)

当我使用 Maven 并传递与 Jvm 参数相同的参数时,它工作得很好。现在我想切换到 Gradle,但我被传递参数所困扰。

小智 0

gradle 有 -P 或 --project-prop 选项。试试这个看看。

-P, --project-prop 设置构建脚本的项目属性