Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Gradle support properties interpolation?

Tags:

gradle

I can't find the syntax of property interpolation in gradle.properties:

prop1 = value
prop2 =${prop1}/lib

Is it supported at all ? Thanks

like image 773
Alexander.Furer Avatar asked May 25 '14 07:05

Alexander.Furer


People also ask

How do you pass properties in Gradle?

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.

What is Gradle properties for?

Last Updated on April 3, 2022. Gradle project properties provide an easy way to customise builds which may need to run differently in certain situations. In this article you'll learn the most effective ways to use and set properties, along with some common scenarios you might come across in your Gradle project.

How do you define properties in build Gradle?

Defining properties via system properties We use the -D command-line option just like in a normal Java application. The name of the system property must start with org. gradle. project , followed by the name of the property we want to set, and then by the value.


1 Answers

gradle.properties is a plain Java properties files, hence String interpolation isn't supported. I recommend to keep all user-defined properties in build.gradle or a separate build script, which provide a much richer configuration language. For example:

gradle/properties.gradle:

ext {
    foo = "foo"
    foobar = "${foo}bar".toUpperCase()
}

build.gradle:

apply from: "gradle/properties.gradle"

println foobar
like image 109
Peter Niederwieser Avatar answered Sep 29 '22 17:09

Peter Niederwieser