4

I just did a clean install. jdk 8 (from adoptium.net) and sbt (using homebrew) on a newly imaged macbook. Somehow homebrew used java 18 anyway, and sbt doesn't work.

I followed the instructions here: https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Mac.html

Following the link on that page to adoptium.net, I found the only jdk 8 for mac os.

$ java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (Temurin)(build 25.322-b06, mixed mode)

Following the instructions on the sbt page, I used homebrew...

$ brew install sbt

When I check the version, I see a problem...

$ sbt about
[info] welcome to sbt 1.6.2 (Homebrew Java 18)
[info] loading project definition from /Users/KHinson1/project
[info] set current project to khinson1 (in build file:/Users/KHinson1/)
[info] This is sbt 1.6.2
[info] The current project is ProjectRef(uri("file:/Users/KHinson1/"), "khinson1") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.15

Homebrew installed it using java 18?! How do I clean this up and use the java 8 that I installed? I can't find java 18 on my laptop.

I immediately run into problems trying to compile a fat jar with sbt assembly...

java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
  at java.base/java.lang.System.setSecurityManager(System.java:416)
  at sbt.TrapExit$.installManager(TrapExit.scala:52)
  at sbt.StandardMain$.runManaged(Main.scala:52)
  at sbt.xMain.run(Main.scala:28)
  at xsbt.boot.Launch$.$anonfun$run$1(Launch.scala:149)
  at xsbt.boot.Launch$.withContextLoader(Launch.scala:176)
  at xsbt.boot.Launch$.run(Launch.scala:149)
  at xsbt.boot.Launch$.$anonfun$apply$1(Launch.scala:44)
  at xsbt.boot.Launch$.launch(Launch.scala:159)
  at xsbt.boot.Launch$.apply(Launch.scala:44)
  at xsbt.boot.Launch$.apply(Launch.scala:21)
  at xsbt.boot.Boot$.runImpl(Boot.scala:78)
  at xsbt.boot.Boot$.run(Boot.scala:73)
  at xsbt.boot.Boot$.main(Boot.scala:21)
  at xsbt.boot.Boot.main(Boot.scala)
[error] [launcher] error during sbt launcher: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release

I know this is a java 17+ problem from questions like this...

sbt assembly cannot create jar getting java.lang.UnsupportedOperationException

I've used homebrew in the past to install sbt, but I'm honestly new to macs and don't understand how it's using java 18 when I didn't install java 18.

How do I get java 18 completely off my machine (I can't even find it) and get sbt installed with java 8 as intended?

Thanks.

edit

I've tried using jenv as outlined here: How can I install openjdk 8 and sbt on mac and have openjdk 8 (not 13) the default one?

I point it at the openjdk I installed

$ which java
/usr/bin/java

but when I try

$ jenv add /usr/bin/java
/usr/bin/java is not a valid path to java installation

(edit I've blown everything out now to try SDKMAN, but I wonder if I should have pointed to /Library/Java/JavaVirtualMachines/temurin_??? directly?)

I tried using brew install sbt@0.13 which lists jdk 8 as its dependency, but it just didn't function ("command not found"). I want a newer sbt, but I think specifying something like sbt.version=1.3.6 in build.properties would force sbt to upgrade later.

I tried "expanding the zip" as suggested on the sbt install page, but same thing ("command not found"), now matter where I expand it to or how I update the path.

edit 2

i'm open to trying sdkman, but at this point I've tried installing/uninstalling a few things, and I don't know how to get java off my machine, and I'm worried about messing it all up with too many competing attempts.

kmh
  • 1,516
  • 17
  • 33
  • 2
    I recommend checking out [sdkman](https://sdkman.io/) and install your jdk/sbt via it. it means you need to remove them from brew first and then reinstall with `sdk`. it allows you to manage different versions of sdks and switch between the versions easily – Ivan Stanislavciuc Apr 16 '22 at 07:14
  • I think you can try `brew doctor` first before anything – chenrui Apr 16 '22 at 18:34

4 Answers4

9

The SDKMAN recommendation by @Ivan Stanislavciuc was a great one. It's really easy how it manages java environments.

Here's my process to back out of my false starts, and get things working.

# uninstall everything
brew uninstall sbt
brew uninstall jenv
cd /Library/Java/JavaVirtualMachines
sudo rm -rf <java installation>

# install sdkman
curl -s "https://get.sdkman.io" | bash

# select java version 
# (I chose temurin jdk 8 which is formerly openj9; 
#  can't find hotspot AdoptOpenJdk anymore, is it gone?)
sdk list java
sdk install java 8.0.322-tem
sdk default java 8.0.322-tem

# install sbt
sdk install sbt

That easy.

I used to use the hotspot adopt open jdk... but I didn't see that one available anywhere now. I see hotspot is still the recommendation on the sbt install page in the SDKMAN instructions (.hs-adpt is "hotspot adopt open jdk"?). But temurin is the openj9 I think, and it matches the adoptium.net link also on the sbt page, so for now I assume that's ok.

kmh
  • 1,516
  • 17
  • 33
2

As far as I know, you can install specific java versions inside brew. Use brew cask install java8 (of course you'll need to have cask installed first, brew install cask).

leo_val
  • 150
  • 8
0

I faced same issue which you mentioned after I changed my Mac and reinstalled sbt. Now since i did not get the exact solution executing this (sudo sbt -java-home /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home assembly ) to run assembly command.

rishikesh
  • 11
  • 2
  • I'd try SDKMAN, and the temurin releases are the new names for what was formerly openj9 adoptOpenJdk. it has cleared up my issues so far. this tutorial is a reasonable quick start: https://reflectoring.io/manage-jdks-with-sdkman/ – kmh Apr 25 '22 at 18:49
-1

I am using java 11, jenv, just did the brew install sbt, there is no problem on my side.

$ java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
$ brew reinstall sbt
...
==> Reinstalling sbt
==> Pouring sbt--1.6.2.all.bottle.tar.gz
==> Caveats
You can use $SBT_OPTS to pass additional JVM options to sbt.
Project specific options should be placed in .sbtopts in the root of your project.
Global settings should be placed in /opt/homebrew/etc/sbtopts

Homebrew's installation does not include `sbtn`.
==> Summary
  /opt/homebrew/Cellar/sbt/1.6.2: 8 files, 3.7MB
$ sbt about
[info] Updated file /Users/rui/Downloads/sbt-test/project/build.properties: set sbt.version to 1.6.2
[info] welcome to sbt 1.6.2 (AdoptOpenJDK Java 11.0.11)
[info] loading project definition from /Users/rui/Downloads/sbt-test/project
[info] set current project to sbt-test (in build file:/Users/rui/Downloads/sbt-test/)
[info] This is sbt 1.6.2
[info] The current project is ProjectRef(uri("file:/Users/rui/Downloads/sbt-test/"), "sbt-test") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.15
[info] Available Plugins
[info]  - sbt.ScriptedPlugin
[info]  - sbt.plugins.CorePlugin
[info]  - sbt.plugins.Giter8TemplatePlugin
[info]  - sbt.plugins.IvyPlugin
[info]  - sbt.plugins.JUnitXmlReportPlugin
[info]  - sbt.plugins.JvmPlugin
[info]  - sbt.plugins.MiniDependencyTreePlugin
[info]  - sbt.plugins.SbtPlugin
[info]  - sbt.plugins.SemanticdbPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.15

I would suggest two things for troubleshooting:

  • checkout PATH thing
  • run brew doctor
chenrui
  • 8,910
  • 3
  • 33
  • 43