【问题标题】:Scala Play making sense of a new project dependencies?Scala Play 理解新项目的依赖关系?
【发布时间】:2015-12-03 01:09:00
【问题描述】:

我下载了最新的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 最新版本?

【问题讨论】:

    标签: scala playframework sbt typesafe-activator


    【解决方案1】:

    play sbt-plugin 将库依赖添加到 play 框架。只需使用该插件,所有必要的依赖项都会被引入。您可以在 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"
    )
    

    【讨论】:

    • 感谢您的回答!这是为什么? sbt 不能解决传递依赖???
    • SBT 可以毫无问题地做到这一点。但是 Play Framework 开发人员采用了插件中的方法,我不知道他们的动机。我可以从源代码中看到它进行了一些条件检查。例如,如果使用 Java,它会引入不同的组件。它似乎将指定正确模块的负担从最终用户身上移开。
    猜你喜欢
    • 2012-04-16
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多