Brew install scala installs openjdk but does not put it in JavaVirtualMachines

Usually when a JDK is added by Brew (e.g. brew cask install adoptopenjdk) it is placed in /Library/Java/JavaVirtualMachines. I just reinstalled Scala and instead of using my JAVA_HOME env variable, it installed openjdk as well.

  1. Why didn’t Brew put openjdk in /Library/Java/JavaVirtualMachine along with my other brew-installed JDKs?
  2. Is there a way to configure the brew install scala formula to just use my existing JAVA_HOME?

Thank you

I believe the answer to question (1) is that adoptopenjdk is a cask but openjdk is not.

  • It explains how to do that in the caveats
  • It will, it’ll just make sure that you have the latest source built version installed as well since testing against casks is highly error prone and the average user experience is better this way.
1 Like

No. It’s because that step requires sudo, which in turn tends to throw up a password prompt, which in turn breaks Homebrew’s CI build/test process for all 3,000+ formulae that depend on Java.

All these formulae are therefore configured to look for OpenJDK in /usr/local/opt/openjdk, which is under Homebrew’s control and doesn’t require any special permissions. That’s how you can run all the Java tools that Homebrew offers (including Scala), without macOS having to know about OpenJDK. You only need to do the linking step in OpenJDK’s caveat if you want to use OpenJDK with the macOS system Java wrapper, a.k.a. /usr/bin/java.

Casks like adoptopenjdk are allowed to prompt the user for their password because it’s the software’s installer package that’s doing so, and that happens only at run time, so it doesn’t affect Homebrew’s CI process.

All the Homebrew Scala wrapper scripts already respect JAVA_HOME if it’s already set, so there’s nothing for you to do there:

$ cat /usr/local/bin/scala
JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk}" exec "/usr/local/Cellar/scala/2.13.3/libexec/bin/scala"  "$@"
1 Like