代码之家  ›  专栏  ›  技术社区  ›  mzrc

sbt,libraryDependencies,无groupID和修订版?

  •  0
  • mzrc  · 技术社区  · 7 年前

    来自sbt documentation ,libraryDependencies格式为:

    libraryDependencies += groupID % artifactID % revision
    

    例如:

    libraryDependencies += "org.postgresql" % "postgresql" % "42.1.4"
    

    然而,在 Play 2.6.x Scala Starter Example 项目 guice公司 构建中的libraryDependencies。仅显示sbt

    libraryDependencies += guice
    

    我们怎么知道是哪个 guice公司 sbt将采用版本或格式用于特定目的?

    1 回复  |  直到 7 年前
        1
  •  1
  •   laughedelic    7 年前

    使用Play Framework时,通常使用 special sbt plugin . 你应该把它放在你的 project/plugins.sbt :

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

    此插件定义不同可选依赖项的值,例如 guice 在你的问题中。因此,您可以转到sbt插件源代码并检查这是什么 guice公司 没错( here ):

    val guice = component("play-guice")
    

    component 定义为

    def component(id: String) = "com.typesafe.play" %% id % play.core.PlayVersion.current
    

    所以它实际上是指 play-guice Play框架和it子项目 depends 在…上 guiceDeps ,定义在 playframework/framework/project/Dependencies.scala :

    val guiceVersion = "4.2.0"
    val guiceDeps = Seq(
      "com.google.inject" % "guice" % guiceVersion,
      "com.google.inject.extensions" % "guice-assistedinject" % guiceVersion
    )
    

    这只是为了说明它是从哪里来的。通常,当您想检查可传递依赖项时,应该使用 sbt-dependency-graph 插件。它可以在sbt shell中列出所有依赖项(及其版本和其他有用信息),或者将其可视化为树或图形。