How to define Gradle's home in IDEA?

2019-01-20 21:28发布

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?

13条回答
forever°为你锁心
2楼-- · 2019-01-20 21:51

C:\Users\<_username>\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3

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

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

查看更多
我命由我不由天
3楼-- · 2019-01-20 21:53

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)

查看更多
4楼-- · 2019-01-20 21:54

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.

查看更多
来,给爷笑一个
5楼-- · 2019-01-20 21:54

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
查看更多
淡お忘
6楼-- · 2019-01-20 22:01

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

查看更多
爷、活的狠高调
7楼-- · 2019-01-20 22:05

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

查看更多
登录 后发表回答