Home > Net >  sbt won't install correctly; homebrew changing java versions
sbt won't install correctly; homebrew changing java versions

Time:04-17

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 [email protected] 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.

CodePudding user response:

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
           
  • Related