[java] Intellij Idea: Importing Gradle project - getting JAVA_HOME not defined yet

Intellij Idea 14.1.4 Mac OS X Yosemite 10.10.3 and later.

From the IDE:

Import Project ->
(Chosen directory to import) ->
Import project from external model, Gradle ->
Gradle Home: /usr/local/Cellar/gradle/2.4/libexec
Gradle JVM: Use JAVA_HOME (not defined yet)

From shell:

echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

(defined in .profile: export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

What am I missing. I have checked other discussions in SO, for example, Intellij JAVA_HOME variable, but don't have Project SDK prompt.

This question is related to java macos intellij-idea gradle

The answer is


Just to add completness to the above selected answer, one can also go the 'Project Setting' windows (if not on the Welcome screen) in IntelliJ IDEA by clicking:

File > Project Structure (Ctrl + Alt + Shift + S)

And can define Project SDK there!


For Windows Platform:

try Running the 64 Bit exe version of IntelliJ from a path similar to following.

note that it is available beside the default idea.exe

"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0\bin\idea64.exe"

link


For MacOS this worked for me without the need to hardcode a particular Java version:

launchctl setenv JAVA_HOME "$(jenv javahome)"

Try starting IntelliJ from terminal. You can find application file under: /Applications/IntelliJ\ IDEA\ 14.app/Contents/MacOS


If you'd like to have your JAVA_HOME recognised by intellij, you can do one of these:

  • Start your intellij from terminal /Applications/IntelliJ IDEA 14.app/Contents/MacOS (this will pick your bash env variables)
  • Add login env variable by executing: launchctl setenv JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"

As others have answered you can ignore JAVA_HOME by setting up SDK in project structure.


Make sure you have a jdk setup. To do this, create a new project and then go to file -> project structure. From there you can add a new jdk. Once that is setup, go back to your gradle project and you should have a jdk to select in the 'Gradle JVM' field.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to intellij-idea

IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Error: Java: invalid target release: 11 - IntelliJ IDEA IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 ERROR Source option 1.5 is no longer supported. Use 1.6 or later Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 How to configure "Shorten command line" method for whole project in IntelliJ intellij idea - Error: java: invalid source release 1.9 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)