Passing jvm arguments to Gradle test task

2019-08-01 02:48发布

问题:

I would like to pass JVM parameters to my Gradle test task. I use the parameters in a Cucumber feature file: ${app.url}. In the build.gradle file, I put those lines:

test {
    testLogging.showStandardStreams = true
    systemProperties System.getProperties()
}

When I execute gradle test -Dapp.url=http://....., I don't see the parameter was passed to the application. I also tried the below, but the result is the same:

test {
    testLogging.showStandardStreams = true
    systemProperty "app.url", System.getProperty("app.url")
}

When I use Maven and pass the same parameters as Jvm arguments, it works fine. Now I would like to switch to the Gradle, but I am stuck with passing parameters.

回答1:

gradle is having -P or --project-prop option. Try this one and see.

-P, --project-prop Set project property for the build script