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?

- 72,696
- 27
- 242
- 420

- 4,043
- 2
- 13
- 5
-
Yeah, the discussion on the JetBrains site seems to indicate it's an issue with symlinks - see reply by Denis.Zhdanov here: http://blog.jetbrains.com/idea/2013/04/gradle-improvements-at-121/ – josh-cain Apr 16 '14 at 00:09
-
1If 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. – Andrew Grimm Oct 19 '16 at 03:33
16 Answers
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}")
}

- 1,512
- 1
- 22
- 40

- 30,998
- 16
- 147
- 256
-
11For those on Linux Mint / Ubuntu, then `/usr/share/gradle` is the output of this gradle script. – Arthur Feb 18 '16 at 23:42
-
3@Steve Happy to help. Tonight I was myself a beneficiary. https://twitter.com/TrentonL/status/729546995686248448 – Trenton May 09 '16 at 05:43
-
4This worked for me, but it's so stupid. I used Gradle's SDK Manager to install Gradle. Why can't IntelliJ use that? – AutonomousApps Oct 25 '16 at 21:20
-
-
@Heath Borders How to get original the command that the gradle script is invoked in build.gradle? https://stackoverflow.com/q/49551995/4385714 – qtopierw Apr 18 '18 at 06:43
-
I am using Ubuntu 18.04 and Gradle 4.10. The script returns /usr/lib/gradle/4.10 – Chathuranga Chandrasekara Sep 11 '18 at 15:16
-
2
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.

- 11,678
- 10
- 56
- 60
-
-
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 Dec 10 '17 at 02:06
-
2@mlo55 much easier to use `export GRADLE_HOME=$(realpath $(brew --prefix gradle))/libexec` – delitescere Oct 19 '18 at 23:38
-
@mlo55 why did you do that in python rather than just calling `which gradle` in the shell? – Mike Young Nov 16 '18 at 15:02
-
@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. – mlo55 Nov 19 '18 at 06:35
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)

- 18,459
- 7
- 30
- 34
If you are using IntelliJ, just do the following.
- Close the project
- (re)Open the project
- you will see "Import gradle project" message on the right bottom. click.
- select "Use default gradle wrapper". not "Use local gradle distribution"
That's all.

- 3,139
- 3
- 33
- 45
-
If you select "Use default gradle wrapper", is not not necessary to supply Gradle home? – Andrew Grimm Oct 19 '16 at 03:23
-
-
1`"Use gradle 'wrapper' task configuration"` worked for me - idk what it means thought – scottysseus Aug 14 '18 at 17:51
-
1If you want IDEA to define your gradle version for you from your actual build script then you select "Use gradle 'wrapper' task configuration" – Cloudish123 Nov 09 '18 at 14:23
-
@AndrewGrimm In my case this radio button is disabled. So I cant select it. Any ideas? – Mikheil Zhghenti Mar 20 '19 at 10:22
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
- 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
(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.

- 847
- 1
- 9
- 14
-
For me no matter what I do, I get: Cause: unable to find valid certification path to requested target – slashdottir Feb 27 '19 at 01:50
-
@slashdottir it may have something to do with the network you are using (if at work or University) or you may need to close IDEA, restart machine, and rebuild from a new project. See https://stackoverflow.com/questions/42415666/errorcause-unable-to-find-valid-certification-path-to-requested-target, even though it is Android-studio it might still be useful. Let me know if any of this helps. – Cloudish123 Feb 27 '19 at 14:25
-
1Finally just switched to building gradle from comand-line - worked out okay that way - thx – slashdottir Feb 28 '19 at 01:03
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

- 4,923
- 6
- 38
- 59
-
1Not very helpful to post a path that only works with your username and particular version numbers. Also not helpful to not propose any solution. – MarkHu Mar 14 '18 at 17:51
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
source .bash_profile
I wrote my own article with instruction in a case if somebody will encounter the same problem.

- 2,808
- 29
- 31
-
Thanks for your answer. For gradle4.7 version : export GRADLE_HOME=/usr/local/Cellar/gradle/4.7/libexec export PATH=$GRADLE_HOME/bin:$PATH – Piash Sarker Apr 24 '18 at 20:07
-
1@PiashSarker, I can see that `/usr/local/opt/gradle/libexec` is a symlink to `/usr/local/Cellar/gradle/4.7/libexec `. If the gradle version will be updated, symlink will be automatically updated as well. Saying that, it is still safer to use `/usr/local/opt/gradle/libexec`. Please correct me if I'm wrong. – skryvets May 09 '18 at 14:37
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)

- 1,779
- 1
- 25
- 36
-
7
-
1That is not an answer at all. What it should be "ideally at" is not what needs to be answered. – wyde19 Nov 07 '17 at 18:11
-
Obviously the version of Gradle will keep going up over the years. Try this to see what you currently have: `ls -d "/Applications/Android Studio.app/Contents/gradle"/*` – MarkHu Mar 14 '18 at 17:46
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

- 609
- 1
- 7
- 10
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

- 10,681
- 15
- 72
- 105
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

- 5,001
- 14
- 58
- 117
Click New -> Project from existing sources -> Import gradle project...
Then Idea recognized gradle automatically.

- 12,471
- 9
- 59
- 68
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...
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

- 121
- 1
- 4