当我使用sbt来构建一个scala项目时,scala的版本有什么关系? [英] What's the relationship of the versions of scala when I use sbt to build a scala project?

查看:549
本文介绍了当我使用sbt来构建一个scala项目时,scala的版本有什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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   

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

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?

推荐答案

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

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使用Scala 2.10
  • sbt 1.x使用Scala 2.12

您可以在project/build.properties中设置此版本,例如:

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

sbt.version = 1.1.1

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

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).

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

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"

同样,它与sbt版本无关.您还可以交叉编译多个Scala版本的代码:

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")

然后,如果在sbt中运行compile,它将使用Scala 2.12.4;如果运行+compile,它将首先使用Scala 2.11.12进行编译,然后使用2.12.4进行编译.有关交叉构建的更多信息,请参见sbt文档.

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.

这篇关于当我使用sbt来构建一个scala项目时,scala的版本有什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆