Disclaimer: I already opened a similar question on Stackoverflow but I believe the number of Scala/sbt users is limited there.
Is there a way to tell SBT to use a different JDK than the one it detects automatically?
I am working on Windows 10 and have an installed JDK 11 for daily use. But I want to use JDK 8 (ZuluFX 8) to compile build my Scala application with sbt.
I was pointed to something called sbt-extras but to me, this looks like a bash script that won’t work on Windows.
Anyone here who could help me? Or should I just go for Gradle and ignore Scala’s own build system?
SBT runs within the JVM, so usually you would use whatever the standard mechanism is to determine which Java you get when you run java, for instance the JAVA_HOME environment variable.
I tried: PS C:\Users\hannes> sbt.bat -java-home C:\opt\Zulu\zulufx-jdk8.0.212-win_x64\
But ended up with an error:
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
[info] Loading global plugins from C:\Users\hannes.sbt\1.0\plugins
[info] Loading project definition from C:\Users\hannes\project
[info] Set current project to hannes (in build file:/C:/Users/hannes/)
[error] Expected symbol
[error] Not a valid command: -
[error] Expected end of input.
[error] Expected ‘–’
[error] Expected ‘debug’
[error] Expected ‘info’
[error] Expected ‘warn’
[error] Expected ‘error’
[error] Expected ‘addPluginSbtFile’
[error] -java-home
[error] ^
Then probably this option is only available with the Linux shell script and you’ll need to set the JAVA_HOME environment variable accordingly - perhaps in yet another batch file that calls sbt.bat.
An easier option is using sdkman, this way you can manage and automate per project intended Java usage. Open terminal at your project root directory and issue sdk env init then open created .sdkmanrc file with text editor of your choice and specify a (previously installed by sdkman) Java then save the file. Any time in future before you run sbt, just type sdk env to dictate intended Java.
FTR, sbt.bat supports the -java-home option since version 1.5.1 (make sure to have at least this version of the launcher, the sbt.version setting in your project’s build.properties file is not relevant)