【问题标题】:Why does sbt use a different version of Scala to the one I asked for?为什么 sbt 使用与我要求的不同版本的 Scala?
【发布时间】:2016-02-02 09:05:10
【问题描述】:

即使我将 scalaVersion 设置为 2.11.7,我的项目还是希望使用 Scala 2.10.x 构建。

每次我重新编译一个新目录 src/main/scala2.10 都会出现在我的项目中。我很确定这一定是 SBT 重新配置的结果,但究竟是什么原因造成的,我该如何解决?

我有一个非常简单的 [project_root]/build.sbt 文件:

name := "coolproduct"

version := "0.0.1"

lazy val scalaVersion = "2.11.7"
lazy val akkaVersion = "2.4.1"

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % akkaVersion

当我运行这个脚本时,它似乎在尝试使用 Scala 2.10 - 与我实际要求的完全不同的版本:

> sbt compile
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\Users\salim\workspace\funproxy\project
[info] Set current project to funproxy (in build file:/C:/Users/salim/workspace/funproxy/)
[info] Updating {file:/C:/Users/salim/workspace/funproxy/}funproxy...
[info] Resolving com.typesafe.akka#akka-actor_2.10;2.4.1 ...
[warn]  module not found: com.typesafe.akka#akka-actor_2.10;2.4.1
[warn] ==== local: tried
[warn]   C:\Users\salim\.ivy2\local\com.typesafe.akka\akka-actor_2.10\2.4.1\ivys\ivy.xml
[warn] ==== jcenter: tried
[warn]   https://jcenter.bintray.com/com/typesafe/akka/akka-actor_2.10/2.4.1/akka-actor_2.10-2.4.1.pom
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.10/2.4.1/akka-actor_2.10-2.4.1.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.typesafe.akka#akka-actor_2.10;2.4.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]  Note: Unresolved dependencies path:
[warn]          com.typesafe.akka:akka-actor_2.10:2.4.1 (C:\Users\salim\workspace\funproxy\build.sbt#L22-23)
[warn]            +- default:funproxy_2.10:0.0.1

我正在运行最新版本的 SBT:

> sbt about
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\Users\salim\workspace\funproxy\project
[info] Set current project to funproxy (in build file:/C:/Users/salim/workspace/funproxy/)
[info] This is sbt 0.13.8
[info] The current project is {file:/C:/Users/salim/workspace/funproxy/}funproxy 0.0.1
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    简短的回答:将lazy val scalaVersion = "2.11.7" 更改为:

    scalaVersion := "2.11.7"
    

    scalaVersion 不仅仅是可以覆盖的本地 scala var(或 val);它在内部定义为 Key (see Keys)。通过:= 操作,您正在更改该键的内部状态。

    【讨论】:

    • 所以我定义了错误的scalaversion - 如果有什么导致它在没有有效的scalaversion键的情况下选择2.10?
    • sbt 默认使用 2.10,因为这是 sbt 本身构建的。没有其他原因。
    猜你喜欢
    • 1970-01-01
    • 2018-12-06
    • 2023-04-04
    • 2022-08-23
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    相关资源
    最近更新 更多