Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set system property using gradle?

Tags:

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
like image 455
markovuksanovic Avatar asked Dec 18 '13 05:12

markovuksanovic


People also ask

How do I set system properties in Gradle?

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.

Where is Gradle system property set?

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.

How do I set environment variables in 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.

How do I set system properties in Java?

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.


1 Answers

This is how I do it, setting props for Selenide test framework:

test {
    systemProperty "browser", "chrome"
    systemProperty "webdriver.chrome.driver", "$projectDir/drivers/chromedriver"
}
like image 81
djangofan Avatar answered Oct 02 '22 16:10

djangofan