How to set a target java version with a sbt project ?
In my build.sbt, I put:
scalacOptions += "-target:jvm-1.6"
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
This seems to be taken into account more or less, because in Project Settings > Compiler > Java Compiler, there were "additional command line parameters" added: "-source 1.6 -target 1.6".
However, when compiling, I'm facing error: "source release 8 requires target release 1.8".
The only SDK on my system (and configured in IDEA) is 1.8.
Is this supposed to work ? (it seems that with plain sbt I can build for target 1.6 with a JDK 1.7).
Please sign in to leave a comment.
Hi!
We've just improved the handling of -source and -target compiler options during SBT project import. Please wait for and install the next nightly plugin build.
Meanwhile, you may manually set Project Settings / Project / Project language level to "1.6".
Thanks for the reporting!
For what it's worth, and if it can help you develop/improve this feature:
- manually changing the "Project language level" causes a prompt to "reload the project". Accepting to do so actually re-runs some SBT stuff in the background, and puts the version back to what it was before
- I noticed that to prevent some warnings (and probably associated problems) when building with SBT manually (outside of IDEA), I also had to add an option:
javacOptions += "-Xbootclasspath...."
pointing to a rt.jar from the target JDK. If my case was not particular, you can expect to find this option associated with "-target".