Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle doesn't work in Intellij - problems with JAVA_HOME

  • I can run gradle from a command line to see its version.
  • I can run, compile and debug a grails app in IntelliJ (version 10.0 or version 10.2)
  • I installed the IntelliJ Gradle Plugin.

Whenever I try to do anything with gradle from within Intellij I get an error as follows:

Executing command: "tasks" Failed to connect to gradle process for command 'tasks'  ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.0\jre  Please set the JAVA_HOME variable in your environment to match the location of your Java installation. 

But in my environment I have JAVA_HOME set to the proper JDK in a different directory. Plus when I look in IntelliJ for the project, it also shows the JDK in the proper JDK location. I cannot find anything that attempts to point the JDK to the Intellij JRE location.

Any ideas please?

like image 364
Andrew Avatar asked Feb 26 '11 01:02

Andrew


People also ask

Does IntelliJ need Java_home?

Do you have Java configured as one of your SDKs in IntelliJ? You don't explicitly require that JAVA_HOME be set if you do.

How do I change the Java Home Path in IntelliJ?

From the main menu, select File | Project Structure | Platform Settings | SDKs. , select the necessary SDK and specify its home directory in the dialog that opens. Only for JDKs: if you don't have the necessary JDK on your computer, select Download JDK.


2 Answers

IntelliJ uses its own jre.

to force IntelliJ to use it, you need to set the environment variable IDEA_JDK to point to your JDK.

then simply restart intellij and gradle gui plugin should now work.

like image 56
Charly Koza Avatar answered Sep 28 '22 08:09

Charly Koza


Man I had so much trouble with this as well, and I don't remember having this much trouble before. I think they changed something. Here are the incantations which got it working for me on Mac OS X 10.11.5, both with Java and Gradle on IntelliJ 2016.1

Here's the summary: install the latest Java JDK from Oracle, add the java_home value to $JAVA_HOME and set that value to $IDEA_HOME (IntelliJ's variable for defining which JDK to use), install gradle (optional) using homebrew, then define the project SDK in IntelliJ.

Here it is broken down from the very beginning of a clean install:

1. Download Java from Oracle's Download Page

2. Use homebrew to install gradle

IntelliJ ships with its own version of Gradle, so this is really optional, and is helpful if you want to use Gradle outside of IntelliJ.

`brew update && brew install gradle` 

3. Set the env variables

Paste the following into ~/.profile. These values will work regardless of which version of java or gradle you have installed. Don't set the GRADLE_HOME if you didn't install the standalone gradle.

export JAVA_HOME=$(/usr/libexec/java_home) export IDEA_JDK=$JAVA_HOME export GRADLE_HOME=/usr/local/opt/gradle/libexec 

4. Set the environment variable to occur at application launch so that IntelliJ sees is using OS X's launchctl program:

launchctl setenv JAVA_HOME $(/usr/libexec/java_home) 

5. Define the project SDK

Use the project settings window in IntelliJ to define the project SDK (I don't see this option anywhere else in the global IntelliJ preferences window, this has to be done in the project settings).

Project Settings

6. Wait for the indexes to update, then close and re-open IntelliJ. You should now be able to build the program.

like image 33
Kyle Falconer Avatar answered Sep 28 '22 08:09

Kyle Falconer