When I run this task:
task tmpTask << { project.properties.each {println " $it"} }
I see:
org.gradle.java.home=/usr/lib/jvm/java-6-oracle
But how to use this variable? I've tried both:
task tmpTask << { println org.gradle.java.home println project.properties.org.gradle.java.home }
But none of this works. First print gives error:
Could not find property 'org' on task ':tmpTask'.
while second fails with:
Cannot get property 'gradle' on null object
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.
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.
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')
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
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