How to define Gradle's home in IDEA?

Intellij IdeaGradle

Intellij Idea Problem Overview


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?

Intellij Idea Solutions


Solution 1 - Intellij Idea

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}")
}

Solution 2 - Intellij Idea

Installed on a Mac via Homebrew, the path

/usr/local/opt/gradle/libexec

is preferable to

/usr/local/Cellar/gradle/X.X/libexec

since the former will survive version upgrades.

Solution 3 - Intellij Idea

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

/usr/local/Cellar/gradle/X.X/libexec

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

Solution 4 - Intellij Idea

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"

enter image description here

That's all.

Solution 5 - Intellij Idea

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: https://www.jetbrains.com/help/idea/gradle-settings.html

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: https://www.jetbrains.com/help/idea/gradle-settings.html

enter image description here

(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:
  
   /usr/local/Cellar/gradle/4.8.1


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

/usr/local/Cellar/gradle/4.8.1/libexec

This is because "libexec is to be used by other daemons and system utilities executed by other programs" (i.e. IDEA). Please see https://unix.stackexchange.com/questions/312146/what-is-the-purpose-of-usr-libexec

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

enter image description here

  1. IDEA should now have allowed you to hit OK enter image description here

Solution 6 - Intellij Idea

C:\Users<_username>\.gradle\wrapper\dists\gradle-<_version>-all<_number_random_maybe>\gradle-<_version>

\Android studio\gradle didn't worked for me.

And "Default gradle wrapper" wasn't configured while importing (cloning) the project from bitbucket

If it causes problem to figure out the path, here is my path :

C:\Users\prabs\.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx\gradle-5.4.1

Solution 7 - Intellij Idea

This is instruction for MAC only. I had the same problem. I solved it by configuring $GRADLE_HOME in .bash_profile. 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

I wrote my own article with instruction in a case if somebody will encounter the same problem.

Solution 8 - Intellij Idea

On a mac it should ideally be at : /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1

(Replace the version string with the latest)

Solution 9 - Intellij Idea

AFAIK it is GRADLE_HOME not GRADLE_USER_HOME (see gradle installation http://www.gradle.org/installation).

On the other hand I played a bit with Gradle support in Idea 13 Cardea and I think the gradle home is not automatically discover by Idea. If so you can file a issue in youtrack.

Also, if you use gradle 1.6+ you can use the Graldle support for setting the build and wrapper. I think idea automatically discover the wrapper based gradle project.

$ gradle setupBuild --type java-library

$ gradle wrapper

Note: Supported library types: basic, maven, java

Regards

Solution 10 - Intellij Idea

If you're using MacPorts, the path is

/opt/local/share/java/gradle

Solution 11 - Intellij Idea

I had to setup the Project SDK before selecting gradle path. Once that was set correctly, I had to choose "Use default gradle wrapper (recommended) in "Import Project from Gradle" dialog.

Still works if I remove gradle using brew:

$ brew remove gradle

enter image description here

Solution 12 - Intellij Idea

This is where my gradle home is (Arch Linux):

/usr/share/java/gradle/

Solution 13 - Intellij Idea

I had some weird errors where it could not find my class, I had to right click on my src folder (was red) to "Make Directory as" -> Source Folder Root

Solution 14 - Intellij Idea

Click New -> Project from existing sources -> Import gradle project...

Then Idea recognized gradle automatically.

Solution 15 - Intellij Idea

I couldn't get it to accept my Gradle JVM selection until I deleted a broken JDK

Th window below is from File -> Other Settings -> Structure For New Projects...

Gradle JVM i.e. JDK home path

I had a red 1.8 JDK SDK entry here, once I deleted that Gradle JVM error below disappeared and I could move on to the next step

Gradle JVM error

Solution 16 - Intellij Idea

In case you are using Mac, most probably your gradle home should be /usr/local/gradle-2.0 for example.

In preference of IDEA search for gradle and set gradle home as given above. It should work

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2699970View Question on Stackoverflow
Solution 1 - Intellij IdeaHeath BordersView Answer on Stackoverflow
Solution 2 - Intellij IdeaTrentonView Answer on Stackoverflow
Solution 3 - Intellij IdeaHasanAboShallyView Answer on Stackoverflow
Solution 4 - Intellij IdeaAndersonView Answer on Stackoverflow
Solution 5 - Intellij IdeaCloudish123View Answer on Stackoverflow
Solution 6 - Intellij IdeaPrabsView Answer on Stackoverflow
Solution 7 - Intellij IdeaskryvetsView Answer on Stackoverflow
Solution 8 - Intellij IdeaAnupamChughView Answer on Stackoverflow
Solution 9 - Intellij IdeajtonicView Answer on Stackoverflow
Solution 10 - Intellij IdeaDaniel ScottView Answer on Stackoverflow
Solution 11 - Intellij Ideauser674669View Answer on Stackoverflow
Solution 12 - Intellij IdeaSevaView Answer on Stackoverflow
Solution 13 - Intellij IdeaBurf2000View Answer on Stackoverflow
Solution 14 - Intellij IdeaMartin PfefferView Answer on Stackoverflow
Solution 15 - Intellij IdeaKevinView Answer on Stackoverflow
Solution 16 - Intellij IdeaRamView Answer on Stackoverflow