问题
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