简体   繁体   English

SBT,Scala版本不匹配

[英]SBT, Scala version mismatch

i have installed Scala 2.11.8 version, and i installed SBT 0.13.12 version as well. 我已经安装了Scala 2.11.8版本,也安装了SBT 0.13.12版本。

when i create one directory and inside that directory typed sbt and sbt prompt opened. 当我创建一个目录并在该目录内键入sbt并打开sbt提示符时。 Inside SBT prompt , when i checked libraryDependencies i found like this: SBT提示符内 ,当我检查libraryDependencies时,我发现是这样的:

sbt:sparkp> libraryDependencies
[info] * org.scala-lang:scala-library:2.12.4

But in machine, i have installed scala 2.11.8 version, when i checked scala -version it shows 但是在机器上,我已经安装了scala 2.11.8版本,当我检查了scala -version时,它显示

hadoop@localhost:~$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL

Did i made any mistake while installing sbt ? 安装sbt时我是否犯了任何错误? or i need to change any configuration properties after installation? 还是安装后需要更改任何配置属性?

please help out. 请帮忙。

Note: There are some questions regarding this error in stackoverflow , but i didn't get exact answer that's why i am asking new question. 注意:关于stackoverflow中的此错误,存在一些问题,但是我没有得到确切的答案,这就是为什么我要问新问题。

The Scala version of a project in SBT is completely unrelated to one you have installed and available from command line. SBT中的一个项目的Scala版本与您已经安装并可以从命令行使用的项目完全无关。 This is a very good thing for several reasons: 这是一件非常好的事情,原因如下:

  1. Everyone who builds a project doesn't get different result depending on Scala version they have installed. 根据他们安装的Scala版本,每个构建项目的人都不会得到不同的结果。

  2. You don't need to install multiple Scala versions and switch between them all the time to work on multiple projects. 您无需一直安装多个Scala版本并在所有版本之间切换就可以处理多个项目。

  3. Many projects should be built with multiple Scala versions, see http://www.scala-sbt.org/0.13/docs/Cross-Build.html . 许多项目应使用多个 Scala版本构建,请参见http://www.scala-sbt.org/0.13/docs/Cross-Build.html

If you are creating a new project, you should specify scalaVersion := "2.11.8" (or any other you want) in build.sbt in this project. 如果要创建新项目,则应在此项目的build.sbt中指定scalaVersion := "2.11.8" (或任何其他想要的名称)。

In my opinion the scala version you are getting is the version with which sbt is built with. 在我看来,您获得的scala版本是构建sbt的版本。

The solution to your is to find global.sbt file which is usually in ~/.sbt/<version>/global.sbt 你的解决办法是找到global.sbt文件通常是在~/.sbt/<version>/global.sbt

and add following line 并添加以下行

scalaVersion := "2.11.8"

Your problem should be solved. 您的问题应该得到解决。

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

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