Che*_*rry 75 dependencies scala sbt
我正在尝试检查文档中描述的SBT依赖树:
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不建树?
Sto*_*ica 131
如果你想实际查看库依赖项(就像你使用Maven那样)而不是任务依赖项(inspect tree显示的是什么),那么你将需要使用sbt-dependency-graph插件.
将以下内容添加到project/plugins.sbt(或全局plugins.sbt)中.
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
然后您可以访问该dependencyTree命令以及其他命令.
gou*_*ama 80
从命令行运行时,发送给sbt的每个参数都应该是一个命令,因此sbt inspect tree clean:
inspect命令,tree命令,clean命令这显然是失败的,因为inspect需要一个论点.这将做你想要的:
sbt "inspect tree clean"
The*_*ect 50
使用 sbt 1.4.0,dependencyTree无需使用插件即可在 sbt 中使用任务。
sbt 依赖树
sbt 1.4.0:https : //github.com/sbt/sbt/releases/tag/v1.4.0
Vas*_*kov 17
如果要查看库依赖项,可以使用以下coursier插件:https://github.com/coursier/coursier/blob/master/doc/FORMER-README.md#printing-trees
输出示例:
 文字(没有颜色):https://gist.github.com/vn971/3086309e5b005576533583915d2fdec4
文字(没有颜色):https://gist.github.com/vn971/3086309e5b005576533583915d2fdec4
请注意,插件与打印树的性质完全不同.它专为快速和并发依赖性下载而设计.但它很好,可以添加到几乎任何项目中,所以我认为值得一提.
我尝试使用"net.virtual-void" % "sbt-dependency-graph"上面提到的插件并得到 9K 行作为输出(有很多空行和重复行),而 Maven 输出中的mvn dependency:tree输出为 ~180 行(我项目中的每个依赖项正好一行)。所以我为那个 Maven 目标写了一个 sbt 包装器任务,一个丑陋的 hack 但它有效:
// 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".!
}
| 归档时间: | 
 | 
| 查看次数: | 57002 次 | 
| 最近记录: |