Scala Play 理解新项目的依赖关系?
Scala Play making sense of a new project dependencies?
我下载了最新的 activator 并按照那里的说明进行安装并创建了一个新的基本 Play 项目。新项目创建成功,但是我无法理解那里的依赖关系。
我看到生成的文件 build.sbt 不包含对 Play 的依赖:
name := """play-template-new"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
相反,我看到在 build/plugins.sbt
下引用了 sbt Play 插件:"
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.3")
// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
// addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
为什么使用 sbt 插件而不是适当的依赖项?如何添加新的依赖项,例如到 Slick 最新版本?
play sbt-plugin 为播放框架添加库依赖。只需使用该插件,所有必要的依赖项都会被引入。您可以在 sbt-plugin 的 source-code 中查看它是如何完成的。
至于添加 slick 依赖项,只需按照 getting started 中所述,以正常的 sbt 方式将以下内容添加到您的 build.sbt 文件中。
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "2.1.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
我下载了最新的 activator 并按照那里的说明进行安装并创建了一个新的基本 Play 项目。新项目创建成功,但是我无法理解那里的依赖关系。
我看到生成的文件 build.sbt 不包含对 Play 的依赖:
name := """play-template-new"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
相反,我看到在 build/plugins.sbt
下引用了 sbt Play 插件:"
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.3")
// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
// addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
为什么使用 sbt 插件而不是适当的依赖项?如何添加新的依赖项,例如到 Slick 最新版本?
play sbt-plugin 为播放框架添加库依赖。只需使用该插件,所有必要的依赖项都会被引入。您可以在 sbt-plugin 的 source-code 中查看它是如何完成的。
至于添加 slick 依赖项,只需按照 getting started 中所述,以正常的 sbt 方式将以下内容添加到您的 build.sbt 文件中。
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "2.1.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)