I started using Gradle and Intellij but I am having problems to configure Gradle\'s JVM. When I start a new Gradle project I am not allowed to define JVM as my JAVA_HOME variabl
So far, nobody has answered the actual question.
Someone can figure what is happening ?
The problem here is that while the value of your $JAVA_HOME
is correct, you defined it in the wrong place.
~/.bash_profile
file. Thus, when you enter echo $JAVA_HOME
, it will return the value that has been set there.~/.bash_profile
… why should it? So to IntelliJ, this variable is not set.There are two possible solutions to this:
"/Applications/IntelliJ IDEA.app/Contents/MacOS/idea"
. The idea
process will inherit any environment variables of Bash that have been export
ed. (Since you did export JAVA_HOME=…
, it works!), or, the sophisticated way:Set global environment variables that apply to all programs, not only Bash sessions. This is more complicated than you might think, and is explained here and here, for example. What you should do is run
/bin/launchctl setenv JAVA_HOME $(/usr/libexec/java_home)
However, this gets reset after a reboot. To make sure this gets run on every boot, execute
cat << EOF > ~/Library/LaunchAgents/setenv.JAVA_HOME.plist
Label
setenv.JAVA_HOME
ProgramArguments
/bin/launchctl
setenv
JAVA_HOME
$(/usr/libexec/java_home)
RunAtLoad
ServiceIPC
EOF
Note that this also affects the Terminal process, so there is no need to put anything in your ~/.bash_profile
.