如何强制 SBT 使用 Java 8? [英] How to force SBT to use Java 8?
本文介绍了如何强制 SBT 使用 Java 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制 SBT 编译为 Java 8 类文件.我添加了 scalacOptions += "-target:jvm-1.8" 但它给出了以下错误消息:
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.8' is not a valid choice for '-target'
[error] bad option: '-target:jvm-1.8'
[error] (compile:compile) Compilation failed
我使用的是 SBT 版本 0.15.5.
I am using SBT version 0.15.5.
我知道我正在使用 Java 8 进行编译,因为我将它添加到 build.sbt,但我仍然想知道为什么 scalacOptions 失败,我不知道 scalac 产生什么输出.
I know I am using Java 8 to compile as I added this to build.sbt, but I still wonder why the scalacOptions fails and I don't know what output the scalac produces.
initialize := {
val _ = initialize.value
if (sys.props("java.specification.version") != "1.8")
sys.error("Java 8 is required for this project.")
}
推荐答案
您的 build.sbt 文件需要以下内容.
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")
}
这篇关于如何强制 SBT 使用 Java 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文