How to install maven with brew but without openjdk?

Viewed 12034

I already have Java HotSpot JDK 11 on my machine that I'm using for everything.

When I typed brew install maven it tried to install openjdk as a dependency. I don't want that and want maven to use my JDK, not its own openjdk.

So, how can I tell it to not install openjdk?

5 Answers

The way I solved it was installing the openjdk with brew (in my case openjdk@8). Mine was different from the default one that brew requires by default. So after that I created a symlink to my openjdk where maven is expecting to find the SDK. And finally installed maven without dependencies.

brew install openjdk@8
cd /usr/local/opt
ln -s ../Cellar/openjdk@8/1.8.0+275 openjdk
brew install --ignore-dependencies maven

After installing java, I have installed Maven with command

brew install --ignore-dependencies maven

It worked for me, for Gradle also.

I don't think there is a supported way to not install a dependency from the command line. However, you can configure the installed mvn to use another JDK. It requires two steps:

  1. Add /usr/local/opt/maven/libexec/bin to your $PATH before /usr/local/bin to pick up the mvn script that does not override $JAVA_HOME

  2. Set $JAVA_HOME in your environment or .mavenrc to pick up the your preferred version of Java

or (building on what Enrique Cordero said above) to re-use an already installed AdoptOpenJDK 8:

brew install adoptopenjdk8
cd /usr/local/opt
ln -s ../Caskroom/adoptopenjdk8/8,275:b01 ./openjdk
brew install maven --ignore-dependencies

and then remove the symlink

rm /usr/local/opt/openjdk

Not exactly the answer for the asked question, but if someone wants to change the JDK path from the default openjdk to the system defined JDK, one can do the following:

First, brew install maven - this will install maven (and openjdk) on the mac and point the default JDK used by maven to be this openjdk

Second, set JAVA_HOME in your ~/.bashrc or ~/.zshrc to point to sytem installed JDK


# set JAVA_HOME for mvn
export JAVA_HOME=`/usr/libexec/java_home`
Related