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条回答
冷血范
2楼-- · 2019-01-20 21:42

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

查看更多
叛逆
3楼-- · 2019-01-20 21:43

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.

查看更多
▲ chillily
4楼-- · 2019-01-20 21:45

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.

查看更多
干净又极端
5楼-- · 2019-01-20 21:46

If you're using MacPorts, the path is

/opt/local/share/java/gradle
查看更多
不美不萌又怎样
6楼-- · 2019-01-20 21:47

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

Then Idea recognized gradle automatically.

查看更多
倾城 Initia
7楼-- · 2019-01-20 21:51

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.

查看更多
登录 后发表回答