Why two different versions of sbt in the project

拜拜、爱过 提交于 2020-01-06 02:48:06

问题


In my Play project I notice that build.properties has sbt version addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.12") and build.properties has sbt.version=0.13.15.

1) Why are there two enteries? 2) What is the difference between them 3) Should their versions be different?


回答1:


There is a difference between SBT proper and SBT plugin. Play Framework is an SBT plugin. The version of SBT is specified in project/build.properties:

sbt.version=0.13.15

whilst the version of Play SBT plugin is specified in project/plugins.sbt:

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

Scala Play SBT plugin (PlayScala) is enabled in build.sbt like so:

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

SBT plugins enrich build definitions with additional useful tasks, commands, settings, and dependencies. Here are some examples from 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")
  ...

So for example to change the default port that Play runs on we can define in build.sbt:

PlayKeys.playDefaultPort := 9009

Note when upgrading SBT version we need to make sure it is compatible with corresponding Play SBT plugin. For example, to use Play with SBT 1 we need to update Play sbt-plugin to 2.6.6.

SBT plugin best practice artifact naming convention encurages the following naming scheme:

sbt-$projectname

For example, sbt-scoverage, sbt-buildinfo, sbt-release, sbt-assembly, however Play named it sbt-plugin, which arguably can be confusing.



来源:https://stackoverflow.com/questions/52352081/why-two-different-versions-of-sbt-in-the-project

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