Ben Chuanlong Du's Blog

It is never too late to learn.

Spcify Java Version to Use in a Scala Project

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")

initialize := {
  val _ = initialize.value
  if (sys.props("java.specification.version") != "1.8")
  sys.error("Java 8 is required for this project.")
}

Using javacOptions ++= Seq("-source", "1.8", "-target", "1.8") does not work if you have no Java sources. But you can set the target JVM for the Scala compiler in build.sbt: scalacOptions += "-target:jvm-1.7"

References

Enforcing Java version for Scala project in sbt?

How to force SBT to use Java 8?

Comments