为什么项目中有两个不同版本的sbt

Why two different versions of sbt in the project

在我的 Play 项目中,我注意到 build.propertiessbt 版本 addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.12") 并且 build.propertiessbt.version=0.13.15.

1) 为什么有两个条目? 2)它们之间有什么区别 3)他们的版本应该不同吗?

SBT 本体和 SBT 插件之间存在差异。 Play Framework 是一个 SBT plugin. The version of SBT 指定在 project/build.properties:

sbt.version=0.13.15

version of Play SBT pluginproject/plugins.sbt 中指定:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.12")

Scala Play SBT 插件 (PlayScala) 在 build.sbt 中启用,如下所示:

lazy val root = (project in file(".")).enablePlugins(PlayScala)

SBT 插件通过额外的有用任务、命令、设置和依赖项丰富构建定义。以下是 Play SBT plugin 中的一些示例:

object PlayKeys {
  val playDefaultPort = SettingKey[Int]("playDefaultPort", "The default port that Play runs on")
  val playDefaultAddress = SettingKey[String]("playDefaultAddress", "The default address that Play runs on")
  val playRunHooks = TaskKey[Seq[PlayRunHook]]("playRunHooks", "Hooks to run additional behaviour before/after the run task")
  ...

例如,要更改 Play 运行的默认端口,我们可以在 build.sbt:

中定义
PlayKeys.playDefaultPort := 9009

注意在升级SBT版本时我们需要确保它与相应的Play SBT插件兼容。 For example,要使用 Play with SBT 1,我们需要将 Play sbt-plugin 更新为 2.6.6

SBT 插件最佳实践 artifact naming convention 鼓励以下命名方案:

sbt-$projectname

例如,sbt-scoveragesbt-buildinfosbt-releasesbt-assembly,但 Play 将其命名为 sbt-plugin,这可能会造成混淆。