Cómo ver el árbol de dependencias en sbt?


Estoy tratando de inspeccionar el árbol de dependencias SBT como se describe en la documentación :

sbt inspect tree clean

Pero obtengo este error:

[error] inspect usage:
[error]   inspect [uses|tree|definitions] <key>   Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.
[error]
[error] inspect
[error]        ^

¿Qué está mal? ¿Por qué SBT no construye el árbol?

Author: Shonzilla, 2014-08-27

4 answers

Cuando se ejecuta desde la línea de comandos , cada argumento enviado a sbt se supone que es un comando, por lo que sbt inspect tree clean:

  • ejecute el comando inspect,
  • luego ejecute el comando tree,
  • luego el comando clean

Esto obviamente falla, ya que inspect necesita un argumento. Esto hará lo que quieras:

sbt "inspect tree clean"
 70
Author: gourlaysama,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-27 06:21:39

Si realmente desea ver las dependencias de la biblioteca (como lo haría con Maven) en lugar de las dependencias de tareas (que es lo que muestra inspect tree), entonces querrá usar el complemento sbt-dependency-graph.

Añade lo siguiente a tu proyecto/plugins.sbt (o los plugins globales.sbt).

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")

Entonces tienes acceso al comando dependencyTree, y a otros.

 87
Author: OrangeDog,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-03 10:20:32

Si desea ver dependencias de la biblioteca , puede usar el complemento coursier: https://github.com/coursier/coursier#printing-trees

Ejemplo de salida: imagen texto (sin colores): https://gist.github.com/vn971/3086309e5b005576533583915d2fdec4

Tenga en cuenta que el plugin tiene una naturaleza completamente diferente a los árboles de impresión. Está diseñado para descargas de dependencias rápidas y simultáneas. Pero es agradable y se puede agregar a casi cualquier proyecto, así que creo que vale la pena mencionarlo.

 13
Author: VasyaNovikov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-02 07:22:08

Intenté usar el complemento "net.virtual-void" % "sbt-dependency-graph" mencionado anteriormente y obtuve 9K líneas como salida(hay muchas líneas vacías y duplicadas) en comparación con ~180 líneas(exactamente una línea para cada dependencia en mi proyecto) como salida en la salida mvn dependency:tree de Maven. Así que escribí una sbt wrapper tarea para ese objetivo Maven, un truco feo pero funciona:

// You need Maven installed to run it.
lazy val mavenDependencyTree = taskKey[Unit]("Prints a Maven dependency tree")
mavenDependencyTree := {
  val scalaReleaseSuffix = "_" + scalaVersion.value.split('.').take(2).mkString(".")
  val pomXml =
    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>groupId</groupId>
      <artifactId>artifactId</artifactId>
      <version>1.0</version>
      <dependencies>
        {
          libraryDependencies.value.map(moduleId => {
            val suffix = moduleId.crossVersion match {
              case binary: sbt.librarymanagement.Binary => scalaReleaseSuffix
              case _ => ""
            }
            <dependency>
              <groupId>{moduleId.organization}</groupId>
              <artifactId>{moduleId.name + suffix}</artifactId>
              <version>{moduleId.revision}</version>
            </dependency>
          })
        }
      </dependencies>
    </project>

  val printer = new scala.xml.PrettyPrinter(160, 2)
  val pomString = printer.format(pomXml)

  val pomPath = java.nio.file.Files.createTempFile("", ".xml").toString
  val pw = new java.io.PrintWriter(new File(pomPath))
  pw.write(pomString)
  pw.close()

  println(s"Formed pom file: $pomPath")

  import sys.process._
  s"mvn -f $pomPath dependency:tree".!
}
 1
Author: MaxNevermind,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-01 20:48:34