【问题标题】:What's the relationship of the versions of scala when I use sbt to build a scala project?使用 sbt 构建 scala 项目时,scala 的版本有什么关系?
【发布时间】:2018-08-06 14:23:53
【问题描述】:

我正在使用 SBT 1.x 构建一个 scala 项目(用 scala 2.11 编写)。有一些“scala 版本”让我感到困惑。

SBT 1.x    => scala 2.12   
SBT plugin => scala 2.x   
My project => scala 2.11   

请帮我弄清楚它们之间有什么区别或关系。以及SBT在编译或运行项目时如何区分它们?

【问题讨论】:

    标签: scala sbt version sbt-plugin


    【解决方案1】:

    sbt 本身及其插件使用的 Scala 版本完全独立于用于编译项目中代码的 Scala 版本。 sbt 版本决定了它使用的 Scala 版本:

    • sbt 0.13 使用 Scala 2.10
    • sbt 1.x 使用 Scala 2.12

    你可以在project/build.properties中设置这个版本,例如:

    sbt.version = 1.1.1
    

    您要使用的 sbt 插件必须与给定版本的 sbt 兼容(许多都与 0.13 和 1.x 交叉编译)。

    要设置项目代码使用的 Scala 版本,请在 build.sbt 中使用 scalaVersion 设置:

    scalaVersion := "2.12.4"
    

    同样,它独立于 sbt 的版本。您还可以为多个 Scala 版本交叉编译您的代码:

    scalaVersion := "2.12.4"
    crossScalaVersions := Seq("2.11.12", "2.12.4")
    

    然后如果你在 sbt 中运行 compile,它将使用 Scala 2.12.4,如果你运行 +compile,它将首先使用 Scala 2.11.12 编译它,然后使用 2.12.4。有关Cross-building 的更多信息,请参阅 sbt 文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-25
      • 2018-01-13
      • 2014-10-24
      • 2015-01-27
      • 2023-04-10
      • 2019-12-25
      • 1970-01-01
      • 2011-02-22
      相关资源
      最近更新 更多