Importing Gradle project - getting JAVA_HOME not defined yet
Intellij Idea 14.1.4
Mac OS X Yosemite 10.10.3
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;
Thanks
请先登录再写评论。
On OSX environment variables for Terminal and for GUI apps are different.
IDEA tries to workaround it by evaluating terminal environment, but it may not work in all cases (depends on how you define environment variables for Terminal). For some reason it doesn't work for your specific case.
See also https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x .
Solution provided at stackoverflow worked
http://stackoverflow.com/questions/31215452
The correct answer (if you want $JAVA_HOME and not just any JDK) is http://stackoverflow.com/a/33559474/27358: assuming you have $JAVA_HOME set in your .bash_profile, you can add the following line:
launchctl setenv JAVA_HOME "$JAVA_HOME"
Note that if you want to set $JAVA_HOME to the latest Java 8, you need
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
(see http://stackoverflow.com/a/6588410/27358)