我正在尝试检查SBT依赖关系树,如documentation中所述
sbt inspect tree clean
但是我得到了这个错误:
[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] ^
怎么啦?为什么SBT不构建树呢?
发布于 2016-05-24 13:14:03
如果您想实际查看库依赖项(与Maven一样),而不是任务依赖项(这是inspect tree
显示的内容),那么您将希望使用sbt-dependency-graph插件。
将以下内容添加到项目/plugins.sbt(或全局plugins.sbt)中。
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
然后,您可以访问dependencyTree
命令和其他命令。
发布于 2018-07-01 20:41:08
我尝试使用上面提到的"net.virtual-void" % "sbt-dependency-graph"
插件,得到了9K行作为输出(有许多空行和重复的行),而在Maven的mvn dependency:tree
输出中,大约有180行(在我的项目中每个依赖项只有一行)作为输出。所以我为那个Maven目标写了一个sbt包装器task,这是一个丑陋的技巧,但它是有效的:
// 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".!
}
发布于 2021-12-13 06:53:09
这对我很有效。参考here用于sbt < 1.3使用:
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")
然后
sbt compile:dependencyTree
https://stackoverflow.com/questions/25519926
复制相似问题