scala 有没有办法在 build.sbt 中定义所需的 sbt 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28429030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:54:43  来源:igfitidea点击:

Is there a way to define the required sbt version in build.sbt?

scalasbt

提问by Bar

In the build.sbt definition of a Scala project, is it possible to define the minimum version of sbt that is required to build the project?

在 Scala 项目的 build.sbt 定义中,是否可以定义构建项目所需的最低 sbt 版本?

回答by dk14

project/build.propertiesallows you to force sbt to use particular version. If current version of installed sbt is different - sbt itself will download (if needed) the version you've specified there:

project/build.properties允许您强制 sbt 使用特定版本。如果安装的 sbt 的当前版本不同 - sbt 本身将下载(如果需要)您在那里指定的版本:

sbt.version=0.12.0

See, Hellofor instance. So actually you may have installed several versions of sbt in your system - it's just jars, that placed in .sbt/boot/scala-{scala.version required by this sbt}/org.scala-sbt/sbt/{sbt.version}folder. Sbt executable actually looks for version specified in project/build.propertiesor (if it's not specified) highest version installed in the system.

看,你好。所以实际上你可能已经在你的系统中安装了几个版本的 sbt - 它只是 jars,放在.sbt/boot/scala-{scala.version required by this sbt}/org.scala-sbt/sbt/{sbt.version}文件夹中。Sbt 可执行文件实际上查找project/build.properties系统中安装的或(如果未指定)最高版本中指定的版本。

P.S. From sbt-launcherperspective, sbt is only one dependency with small non-intersecting others like ansi.jar, so specifying the range of versions like [0.13.1, 0.13.8]have no much sense as it would be efective only for conflicting transitive deps. Otherwise it's enough to specify higher possible version (which would compile) - you may even choose some version that you already have (and update project's sbt that way).

PS 从sbt-launcher角度来看, sbt 只是一个与其他小的不相交的依赖项,例如ansi.jar,因此指定版本范围[0.13.1, 0.13.8]没有多大意义,因为它仅对冲突的传递依赖项有效。否则,指定更高的可能版本(将编译)就足够了 - 您甚至可以选择一些您已经拥有的版本(并以这种方式更新项目的 sbt)。