What's the relationship of the versions of scala when I use sbt to build a scala project?

a 夏天 提交于 2020-01-28 05:22:32

问题


I'm building a scala project(writen in scala 2.11) with SBT 1.x.There are a few "versions of scala" which made me puzzle.

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

Please help me to figure out what's the difference or relationship between them.And how SBT tells them apart when compiling or running the project?


回答1:


The Scala version used by sbt itself and its plugins is completely independent from the Scala version used to compile the code in your project. The sbt version determines the Scala version it uses:

  • sbt 0.13 uses Scala 2.10
  • sbt 1.x uses Scala 2.12

You can set this version in project/build.properties, for example:

sbt.version = 1.1.1

The sbt plugins you want to use have to be compatible with the given version of sbt (and many are cross-compiled with both 0.13 and 1.x).

To set the version of Scala you want to use for the code in you project, use scalaVersion setting in your build.sbt:

scalaVersion := "2.12.4"

Again, it's independent from the version for sbt. You can also cross-compile your code for several Scala versions:

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

Then if you run compile in sbt, it will use Scala 2.12.4, and if you run +compile, it will first compile it with Scala 2.11.12 and then with 2.12.4. See sbt docs for more about Cross-building.



来源:https://stackoverflow.com/questions/49000201/whats-the-relationship-of-the-versions-of-scala-when-i-use-sbt-to-build-a-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!