How to obtain 'gradle_home' in gradle build when using wrapper


(kallin.nagelberg) #1

I’m trying to find what is effectively ‘gradle_home’ when using the wrapper. I want to know this so that I can setup my Intellij project files to automatically know how to run gradle tasks. I’m doing this:

CURRENT_GRADLE_VERSION = '1.3'
idea.project.ipr {
    withXml { xml ->
          def wrapperPath = "${System.properties['user.home']}/.gradle/wrapper/dists/gradle-$CURRENT_GRADLE_VERSION-bin"
        def wrapperHome = new File(wrapperPath)
        def uniqueId = wrapperHome.list()[0]
        def uniqueHome = new File("$wrapperPath/$uniqueId/gradle-$CURRENT_GRADLE_VERSION")
          def projectRoot = xml.asNode()
          def existingNode = projectRoot.component.find {
            it.@name == 'GradleSettings'
        }
        if (existingNode) {
            projectRoot.remove(existingNode)
        }
          projectRoot.appendNode('component', [name: 'GradleSettings']).appendNode('option', [name: 'gradleHome', value: uniqueHome])
    }
}

Is there an easier way to obtain that ‘uniqueHome’ value?

Thanks, -Kal


(Peter Niederwieser) #2

Have you tried ‘gradle.gradleHomeDir’?


(kallin.nagelberg) #3

Genius! Thanks :slight_smile:

Ref to the API for future reference:

http://gradle.org/docs/current/javadoc/org/gradle/api/invocation/Gradle.html