How to give System property to my test via Gradle and -D

前端 未结 5 439
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 00:14

I have a a Java program which reads a System property

System.getProperty(\"cassandra.ip\");

and I have a Gradle build file that I start wit

5条回答
  •  既然无缘
    2020-11-29 00:30

    I had a case where I needed to pass multiple system properties into the test JVM but not all (didn't want to pass in irrelevant ones). Based on the above answers, and by using subMap to filter the ones I needed, this worked for me:

    task integrationTest(type: Test) {
        // ... Do stuff here ...
        systemProperties System.getProperties().subMap(['PROP1', 'PROP2'])
    }
    

    In this example, only PROP1 and PROP2 will be passed in, if they exist in gradle's JVM.

提交回复
热议问题