How to force SBT to use Java 8?

前端 未结 2 884
青春惊慌失措
青春惊慌失措 2020-12-15 16:35

How can I force SBT to compile to Java 8 class files. I added scalacOptions += \"-target:jvm-1.8\" but it gives the following error message:

[error] \'jvm-1         


        
2条回答
  •  甜味超标
    2020-12-15 16:45

    You need the following on your build.sbt file.

    javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
    
    initialize := {
      val _ = initialize.value
      val javaVersion = sys.props("java.specification.version")
      if (javaVersion != "1.8")
        sys.error("Java 1.8 is required for this project. Found " + javaVersion + " instead")
    }
    

提交回复
热议问题