How to use gradle properties in build.gradle

For anyone else's benefit. If the property you define is not dot separated, then you can simply refer to it directly.

In your gradle.properties:

myProperty=This is my direct property
my.property=This is my dotted property with\t\t tabs \n and newlines

In your build.gradle:

// this works
println myProperty
println project.property('my.property')

// this will not
println my.property

project.properties is a Map<String, ?>

So you can use

project.properties['org.gradle.java.home']

You can also use the property() method (but that looks in additional locations):

project.property('org.gradle.java.home')

From gradle.properties

Add prop to the file gradle.properties

hi1=hi

From CommandLine

Add -Pxxx end of command line.

./gradlew -q readPropertiesTask -Phi2=tete

Several properties:

./gradlew -q readPropertiesTask -Phi2=tete -Phi3=rr

How to read?

val propFromFile = project.properties["hi1"]
println("propFromFile = $propFromFile")