我正在尝试按照documentation:
中的描述检查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构建树?
答案 0 :(得分:114)
如果你想实际查看库依赖项(就像你使用Maven那样)而不是任务依赖项(inspect tree
显示的那个),那么你将需要使用sbt-dependency-graph插件
将以下内容添加到项目/ plugins.sbt(或全局plugins.sbt)。
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
然后您可以访问dependencyTree
命令和其他命令。
答案 1 :(得分:78)
从命令行运行时,发送给sbt的每个参数都应该是一个命令,因此sbt inspect tree clean
将:
inspect
命令tree
命令clean
命令这显然失败了,因为inspect
需要一个参数。这将做你想要的:
sbt "inspect tree clean"
答案 2 :(得分:15)
如果您想查看库依赖项,可以使用coursier
插件:https://github.com/coursier/coursier/blob/master/doc/FORMER-README.md#printing-trees
输出示例: 文字(没有颜色):https://gist.github.com/vn971/3086309e5b005576533583915d2fdec4
请注意,插件与打印树的性质完全不同。它专为快速和并发依赖性下载而设计。但它很好,几乎可以添加到任何项目中,所以我认为值得一提。
答案 3 :(得分:9)
使用sbt 1.4.0,无需使用插件即可在sbt中使用dependencyTree
任务。
sbtdependencyTree
答案 4 :(得分:3)
我尝试使用上面提到的> ## Minimal example with a list of vectors
> # Creating list
> mylist = rep(list(1:3), 3)
>
> # Vector on which I will base the replacement
> myvec = 1:3
>
> # Replacing 1s by NA
> for(i in 1:length(mylist)){
+ mylist[[i]] = sapply(mylist[[i]], function(x) x[x ==myvec[i]] = NA)
+ }
>
> # But I get NAs for every observation
> mylist
[[1]]
[1] NA NA NA
[[2]]
[1] NA NA NA
[[3]]
[1] NA NA NA
>
> # This is what I wanted:
> list(c(NA, 2, 3), c(1, NA, 3), c(1, 2, NA))
[[1]]
[1] NA 2 3
[[2]]
[1] 1 NA 3
[[3]]
[1] 1 2 NA
>
>
> ## More complex example, with a list of lists of vectors that more closely approximates my data structure
> # Creating list of lists
> mynewlist = rep(list(rep(list(1:3), 3)), 3)
>
> # Replacing 1s by NAs
> for(i in 1:length(mynewlist)){
+ mynewlist[[i]] = lapply(mynewlist[[i]], function(x) x[x ==myvec[i]] = NA)
+ }
>
> # But now each vector becomes a single NA
> mynewlist
[[1]]
[[1]][[1]]
[1] NA
[[1]][[2]]
[1] NA
[[1]][[3]]
[1] NA
[[2]]
[[2]][[1]]
[1] NA
[[2]][[2]]
[1] NA
[[2]][[3]]
[1] NA
[[3]]
[[3]][[1]]
[1] NA
[[3]][[2]]
[1] NA
[[3]][[3]]
[1] NA
>
> # What I wanted:
> list(rep(list(c(NA, 2, 3)), 3), rep(list(c(1, NA, 3)), 3), rep(list(c(1, 2, NA)), 3))
[[1]]
[[1]][[1]]
[1] NA 2 3
[[1]][[2]]
[1] NA 2 3
[[1]][[3]]
[1] NA 2 3
[[2]]
[[2]][[1]]
[1] 1 NA 3
[[2]][[2]]
[1] 1 NA 3
[[2]][[3]]
[1] 1 NA 3
[[3]]
[[3]][[1]]
[1] 1 2 NA
[[3]][[2]]
[1] 1 2 NA
[[3]][[3]]
[1] 1 2 NA
插件,并获得了9K行作为输出(有很多空行和重复项),而输出为〜180行(对于我的项目中的每个依赖项实际上只有一行)在Maven的> # Creating list of lists
> mynewestlist = rep(list(rep(list(1:3), 3)), 3)
>
> # Replacing 1s by NAs
> for(i in 1:length(mynewestlist)){
+ mynewestlist[[i]] = lapply(mynewestlist[[i]], function(x) ifelse(x ==myvec[i], NA, x))
+ }
>
> # That's better:
> mynewestlist
[[1]]
[[1]][[1]]
[1] NA 2 3
[[1]][[2]]
[1] NA 2 3
[[1]][[3]]
[1] NA 2 3
[[2]]
[[2]][[1]]
[1] 1 NA 3
[[2]][[2]]
[1] 1 NA 3
[[2]][[3]]
[1] 1 NA 3
[[3]]
[[3]][[1]]
[1] 1 2 NA
[[3]][[2]]
[1] 1 2 NA
[[3]][[3]]
[1] 1 2 NA
> list(rep(list(c(NA, 2, 3), 3), rep(list(1, NA, 3), 3), rep(list(1, 2, NA), 3))
输出中。所以我为那个Maven目标写了一个sbt包装器task,这是一个丑陋的骇客,但它确实有效:
"net.virtual-void" % "sbt-dependency-graph"