Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a user environment variable in gradle.properites

In a gradle task I can create a path like this:

System.env.FOLDER_PATH + '/subFolder'

but I would like to set this in my gradle.properties instead, so it would be something like

subFolderPath=${System.env.FOLDER_PATH}/subFolder

but I can't find any examples of this, is it even possible?

like image 814
President Comacho Avatar asked Oct 10 '14 23:10

President Comacho


People also ask

How are environment variables used in Gradle properties?

Gradle can also set project properties when it sees specially-named system properties or environment variables. If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue , then Gradle will set a prop property on your project object, with the value of somevalue .

How do I declare a variable in Gradle?

Local variables are declared with the def keyword. They are only visible in the scope where they have been declared. Local variables are a feature of the underlying Groovy language. Local variables are declared with the val keyword.

Do we need to set environment variables for Gradle?

Environment variables are needed to customise the execution of the gradle tasks. Below is the working code in gradle 7.3.


1 Answers

gradle.properties is a plain Java properties file. It can only contain literal key/value pairs.

like image 86
Peter Niederwieser Avatar answered Oct 02 '22 19:10

Peter Niederwieser