338

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.

Mel
  • 5,837
  • 10
  • 37
  • 42
bentobox
  • 3,948
  • 2
  • 16
  • 10

7 Answers7

670

You need to setup a SDK for Java projects, like @rizzletang said, but you don't need to create a new project, you can do it from the Welcome screen.

On the bottom right, select Configure > Project Defaults > Project Structure: enter image description here

Picking the Project tab on the left will show that you have no SDK selected:

enter image description here

Just click the New... button on the right hand side of the dropdown and point it to your JDK. After that, you can go back to the import screen and it should just show up.

visola
  • 7,493
  • 1
  • 17
  • 21
  • 31
    Once I clicked on "JDK" from the dropdown, I simply accepted the default folder (Home). I then accepted the defaults for that directory (when opening). Intellij did a *lot* of thinking...and it seemed to work. Thanks! – SMBiggs Sep 15 '15 at 16:49
  • 3
    Thanks!!! Really ridiculous that it's so complicated to get started with a first java / gradle project with intelliJ. I mean, if intelliJ can start, it MUST already know something about java being installed on the system, why not add this java by default already...maybe some of their developers will care one day. – Henning Oct 26 '17 at 11:41
  • Great! BTW, if you have an open project, Default Project Structure... dialog can be accessed via File > Other Settings. – Dima Korobskiy Nov 14 '17 at 22:53
  • 2
    IntelliJ people must be paid by the number of clicks they force you to go through. There is no other reason to bury a simple and important setting under 5 levels of obscurity, unless of course, they are competing with Microsoft for the award of sh**est product of the year. – Abhijit Sarkar Nov 24 '17 at 18:45
37

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.

gk0
  • 491
  • 5
  • 4
  • 1
    This blog post gives more info on launchctl and how certain locations of .launch.conf are deprecated for newer MacOS. http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-slash-etc-slash-launchd-dot-conf/ – George Pantazes Jul 13 '17 at 19:06
5

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

Community
  • 1
  • 1
Iman
  • 17,932
  • 6
  • 80
  • 90
  • Advice for how to set this up on windows won't be very useful given the scope of this question is for a different platform. – Conrad.Dean Feb 11 '16 at 17:07
  • 2
    @Conrad.Dean , you are right. but i end up here when searching for the same error in windows, and this may help some one with similar case. thanks anyway for the comment – Iman Feb 12 '16 at 08:48
3

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!

akhouri
  • 3,065
  • 3
  • 25
  • 29
2

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

launchctl setenv JAVA_HOME "$(jenv javahome)"
Dmitry Chornyi
  • 1,821
  • 4
  • 25
  • 33
  • The actual command worked for me **% launchctl setenv JAVA_HOME `/usr/libexec/java_home`** – Vagif Dec 07 '17 at 16:03
1

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.

rizzletang
  • 61
  • 4
0

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

hraut
  • 1
  • 1