groovygradlejava-home

How to use gradle properties in build.gradle


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

Solution

  • 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')