简体   繁体   中英

sbt, libraryDependencies without groupID and revision?

From sbt documentation , the libraryDependencies format is:

libraryDependencies += groupID % artifactID % revision

For example:

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

However, in the Play 2.6.x Scala Starter Example project, the guice libraryDependencies in build.sbt shows only

libraryDependencies += guice

How do we know which guice version will be adopted by sbt or the format is for some specific purpose?

When you use Play Framework, you normally setup your project using the special sbt plugin . You should have it in your project/plugins.sbt :

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

This plugin defines values for different optional dependencies such as guice in your question. So you can go to the sbt plugin source and check what is this guice exactly ( here ):

val guice = component("play-guice")

And component is defined as

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

So it actually refers to the play-guice subproject of the Play framework and it depends on guiceDeps , which are defined in the 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
)

This is just to show where does it come from. Normally, when you want to check your transitive dependencies, you should use sbt-dependency-graph plugin. It can list all your dependencies (with their versions and other useful information) in the sbt shell or visualize it as a tree or a graph.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM