I was wondering if it's possible to set a system property, for a Java application, using Gradle?
I tried using gradle.properties file and defining a property as
systemProp.name = my name
but then when I try to get that property from a Java application using
System.getProperty("name")
that property is not found.
build.gradle and gradle.properties are in root folder of the project.
This is what my build.gradle looks like:
apply plugin: 'war'
apply plugin: 'appengine'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.8.6'
}
}
appengine {
httpPort = 8081
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.inject.extensions', name: 'guice-servlet', version: '3.0'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.2.0.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.8.6'
compile 'com.google.template:soy:2012-12-21'
compile 'org.json:json:20090211'
}
And this is what my build.properties look like:
systemProp.firstName=Marko
systemProp.lastName=Vuksanovic
This is part of an AppEngine application and I run it using the following command:
gradle appengineRun
System properties Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.
You can also set system properties in gradle. properties files with the prefix systemProp. In a multi project build, “ systemProp. ” properties set in any project except the root will be ignored. That is, only the root project's gradle.
Click on Environment variables. After that, click the New option. Now, create user variable, enter the variable name as Gradle_Home and paste the value of the home path e.g., C:\gradle-6.0. 1 in the variable value field.
Programmatically, a system property can be set using the setProperty method of the System object, and also via the setProperty method of the Properties object that can be obtained from System via getProperties.
This is how I do it, setting props for Selenide test framework:
test {
systemProperty "browser", "chrome"
systemProperty "webdriver.chrome.driver", "$projectDir/drivers/chromedriver"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With