I am trying to run a scala program, in which there are errors with Java 16. My colleague is using Java 15, and all is fine. When i type java -version in my terminal it says i am using Java 15. However, when i run sbt run -v, it says it is using Java 16, and thus the program throws errors.
I am seeing people talk about this sbt-extra thing, but not a whole lot of explanation on how to use it. I do not even have Java 16 installed on my Mac, so I am really confused as to why SBT says this.
The best way is to do this via the build.sbt file so then it's specific to just that project not your entire local environment. I.e. add the following to build.sbt:
javacOptions ++= Seq("-source", "11", "-target", "11")
Add this to ~/.bash_profile, ~/.bashrc or ~/.zshrc (depending on shell preferences/OS), or just run this before running sbt in a terminal:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
It's better though to do this per-sbt project via build.sbt as per this answer: https://stackoverflow.com/a/76456295/1586965
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With