简体   繁体   English

为什么sbt使用与我要求的版本不同的Scala版本?

[英]Why does sbt use a different version of Scala to the one I asked for?

It even though I have scalaVersion set to 2.11.7, my project wants to build with Scala 2.10.x. 即使将scalaVersion设置为2.11.7,我的项目仍希望使用Scala 2.10.x进行构建。

Every time I recompile a new directory src/main/scala2.10 appears in my project. 每次我重新编译一个新目录src / main / scala2.10都会出现在我的项目中。 I'm pretty sure that this must be the result of an SBT reconfiguration, but what exactly is causing this, and how do I fix it? 我很确定这一定是SBT重新配置的结果,但是究竟是什么原因导致的呢?如何解决呢?

I have a very simple [project_root]/build.sbt file: 我有一个非常简单的[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

When I run this script it seems to be trying to use Scala 2.10 - a totally different version to what I actually asked for: 当我运行此脚本时,似乎正在尝试使用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

I'm running an up to date version of SBT: 我正在运行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

The short answer: change lazy val scalaVersion = "2.11.7" to: 简短的答案:将lazy val scalaVersion = "2.11.7"更改为:

scalaVersion := "2.11.7"

scalaVersion is not just a local scala var (or val ) you can override; scalaVersion是可以覆盖的本地scala var (或val ); it's defined internally as a Key ( see Keys ). 它在内部定义为Key( 请参阅Keys )。 With the := operation you're changing the internal state of that key. 使用:=操作,您可以更改该键的内部状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM