我尝试使用"net.virtual-void" % "sbt-dependency-graph"
上述插件,并获得了9K行作为输出(有许多空行和重复项),而Maven输出中的mvn dependency:tree
输出为〜180行(对于我的项目中的每个依赖项实际上只有一行)。所以我为那个Maven目标写了一个sbt包装器任务,这是一个丑陋的hack,但是它可以工作:
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".!
}