How to define Gradle's home in IDEA?

gradle tutorial
gradle build command
gradle dependencies
gradle project
gradle dependencies task
gradle buildscript
gradle environment variable
gradle version

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment variable set (to what I think is!) the correct path, and I have been able to successfully import this same project into Eclipse. Any suggestions?

You can write a simple gradle script to print your GRADLE_HOME directory.

task getHomeDir {
    doLast {
        println gradle.gradleHomeDir

and name it build.gradle.

Then run it with:

gradle getHomeDir

If you installed with homebrew, use brew info gradle to find the base path (i.e. /usr/local/Cellar/gradle/1.10/), and just append libexec.

The same task in Kotlin in case you use build.gradle.kts:

tasks.register("getHomeDir") {
    println("Gradle home dir: ${gradle.gradleHomeDir}")

Writing Build Scripts, to declare dependencies. as a consumer, to resolve a set of dependencies to files. as a producer, to expose artifacts and their dependencies for consumption  Here's how you do it: Open .bash_profile (usually it's located in the user’s home directory). Add the following lines to update $PATH variable: export GRADLE_HOME=/usr/local/opt/gradle/libexec export PATH=$GRADLE_HOME/bin:$PATH. Save it. Apply your changes by running source .bash_profile.

Installed on a Mac via Homebrew, the path


is preferable to


since the former will survive version upgrades.

Declaring dependencies, Gradle's build-by-convention support adds a more concrete definition for what a For now, we will look at defining some simple tasks in a build with one project. Define a Gradle task to bundle web assets with Webpack in a way that leverages Gradle's up-to-date checks and build cache. Demonstrate the caching behavior and incremental build capabilities.

If you installed gradle with homebrew, then the path is:


Where X.X is the version of gradle (currently 2.1)

Build Script Basics, First you set up a Java project for Gradle to build. To keep the focus on Gradle, make the project as simple as possible for  The first time you run the wrapper for a specified version of Gradle, it downloads and caches the Gradle binaries for that version. The Gradle Wrapper files are designed to be committed to source control so that anyone can build the project without having to first install and configure a specific version of Gradle.

If you are using IntelliJ, just do the following.

  1. Close the project
  2. (re)Open the project
  3. you will see "Import gradle project" message on the right bottom. click.
  4. select "Use default gradle wrapper". not "Use local gradle distribution"

That's all.

Getting Started, to set specific JVM options for Gradle. are usually defined via the system property UI. Gradle uses the same logic as Maven to identify the location of your local Maven cache. If a local repository location is defined in a settings.xml , this location will be used. The settings.xml in USER_HOME /.m2 takes precedence over the settings.xml in M2_HOME /conf .

This is what helped me solve the problem of not having Gradle home set for the IDEA when importing a Gradle project.

THREE OPTIONS -- (A) Default Wrapper (B) "gradle 'wrapper' task configuration" OR (C) "local gradle distribution" defined by jetbrains:

A. Default Wrapper (recommended)

If you are able, select this recommended option. If it is grayed out, see option C, which should then set your default for all subsequent projects.

B. Gradle 'Wrapper' Task Configuration

If you want IDEA to define your gradle version for you from your build script

  1. Set this option if you define your gradle build versions as a task within your actual gradle build.

Example below from jetbrains:

(useful if you do not want to share gradle builds between projects)

C. Local Gradle Distribution

1. Run the following command to get gradle location:

   brew info gradle (if gradle was installed with homebrew)

2. You are looking for something like this:


3. Next, append 'libexec' to the gradle location you just found:


This is because "libexec is to be used by other daemons and system utilities executed by other programs" (i.e. IDEA). Please see

4. Finally, put that new path in the Gradle home input box if IDEA prompts you.

  1. IDEA should now have allowed you to hit OK

The Gradle build system- Tutorial, Declaring Your Dependencies. Dependency configuration is nothing but defines set of dependences. You can use this feature to declare external dependences  In order to do so, Gradle first normalizes both inputs and then compares the result. For example, for a compile classpath, Gradle extracts the ABI signature from the classes on the classpath and then compares signatures between the last Gradle run and the current Gradle run as described in Java compile avoidance.

Gradle - Dependency Management, This chapter explains about what is task and how to generate and execute a task. Defining Tasks. Task is a keyword which is used to define a task into build script. When Gradle executes a Groovy build script (.gradle), it compiles the script into a class which implements Script. This means that all of the properties and methods declared by the Script interface are available in your script.

Gradle - Tasks, Gradle is an open-source build automation system that builds upon the concepts of Apache Ant Gradle uses a directed acyclic graph to determine the order in which tasks can be run. Gradle was designed for multi-project builds, which can  Gradle represents the scope of a dependency with the help of a Configuration. Every configuration can be identified by a unique name. Many Gradle plugins add pre-defined configurations to your project.

Gradle, // For each source set, you can specify only one Android manifest. // The following points Gradle to a different manifest for this source set. manifest. Gradle allows you to define one or more default tasks for your build (build.gradle file). Look at the below example: defaultTasks will declare the default tasks in your build. defaultTasks 'clean', 'run' task clean << { println 'Default Task - Cleaning!' } task run << { println 'Default Task - Running!' } task mySpecTask << { println "I'm not a default task!"

  • Yeah, the discussion on the JetBrains site seems to indicate it's an issue with symlinks - see reply by Denis.Zhdanov here:
  • Good question. Would you like to select a valid answer for this. Don't go by the points - I would suggest @trenton's. You might also want to mention the OS this was about in the question.
  • If you choose "Use default gradle wrapper (recommended)", you don't need to set Gradle Home. Unfortunately, they don't grey out the input box for it - they merely indicate that it's disabled by the type of cursor that you have when you mouse over it.
  • For those on Linux Mint / Ubuntu, then /usr/share/gradle is the output of this gradle script.
  • @Steve Happy to help. Tonight I was myself a beneficiary.
  • This worked for me, but it's so stupid. I used Gradle's SDK Manager to install Gradle. Why can't IntelliJ use that?
  • On Fedora 25 that's /usr/share/gradle too.
  • For Arch Linux it is: /usr/share/java/gradle
  • This is also the case for Android Studio (as of AS 1.3, anyway).
  • Nice one, I ended up using this beast to set my GRADLE_HOME (to prevent issues when upgrading gradle with brew) export GRADLE_HOME=`python -c "import os; print(os.path.realpath('$(which gradle)'))" | xargs dirname | xargs dirname | xargs printf "%s/libexec"` If anyone can simplify, that would be handy too :)
  • @mlo55 much easier to use export GRADLE_HOME=$(realpath $(brew --prefix gradle))/libexec
  • @mlo55 why did you do that in python rather than just calling which gradle in the shell?
  • @MikeYoung , I didn't have realpath installed installed at the time. nb: I now use export GRADLE_HOME="$(brew --prefix gradle)/libexec/" as recommended by @delitescene. Compare ls "$(brew --prefix gradle)/libexec/" with ls "$(which gradle)/libexec/" on osx, if u r using brew.
  • If you select "Use default gradle wrapper", is not not necessary to supply Gradle home?