Search code examples
gradlesystem-properties

How to pass system properties to the tests in gradle in the smart way?


build.gradle

tasks.withType(Test){
    systemProperties=System.properties
    println systemProperties['param']
}

Now I can either pass parameters in the command line:

gradle test -Dparam=10

or put them in gradle.properties:

systemProp.param=15

Ideally I would like to put the defaults in the gradle.properties, and be able to overwrite them from the command line. Unfortunately if I do that, the gradle.properties has precedence, and -Dparam=10 is ignored.

Could you offer any solutions on that?


Solution

  • https://issues.gradle.org/browse/GRADLE-2122

    It works since 2.12 or 2.13 "the smart way" already!

    The example above is working, the command line -D option overdrives the defaults in gradle.properties