hym1224 / note

1 stars 0 forks source link

build gradle set -Dkey=value #13

Open hym1224 opened 6 years ago

hym1224 commented 6 years ago

https://stackoverflow.com/questions/23689054/problems-passing-system-properties-and-parameters-when-running-java-class-via-gr

http://mrhaki.blogspot.jp/2015/09/gradle-goodness-pass-java-system.html

hym1224 commented 6 years ago

http://mrhaki.blogspot.jp/2015/09/gradle-goodness-pass-java-system.html

Gradle is of course a great build tool for Java related projects. If we have tasks in our projects that need to execute a Java application we can use the JavaExec task. When we need to pass Java system properties to the Java application we can set the systemProperties property of the JavaExec task. We can assign a value to the systemProperties property or use the method systemProperties that will add the properties to the existing properties already assigned. Now if we want to define the system properties from the command-line when we run Gradle we must pass along the properties to the task. Therefore we must reconfigure a JavaExec task and assign System.properties to the systemProperties property.

In the following build script we reconfigure all JavaExec tasks in the project. We use the systemProperties method and use the value System.properties. This means any system properties from the command-line are passed on to the JavaExec task.