如何使用Gradle以扁平形式获取我的项目依赖项列表? [英] How can I get a list of my projects dependencies in a flattened form using Gradle?
问题描述
我知道Gradle具有出色的依赖关系
任务,它列出了项目的所有依赖关系。但是,它将它们返回到树形目录中。
我想列出所有依赖关系,因为它们只是在一个扁平列表中解析。类似于Maven依赖项插件 list
目标的行为。
是一个满足这种需求的短任务:
pre $ task('dependenciesList')<< {
println编译依赖关系
def selectedDeps = project.configurations.compile.incoming.resolutionResult.allDependencies.collect {dep - >
$ {dep.selected}
}
selectedDeps.unique()。sort()。each {println it}
}
第三行是有趣的部分。您需要获得您关心的(编译)配置,然后获取依赖关系, incoming.resolutionResult
将提供已解析的值和版本。
I know that Gradle has the excellent dependencies
task that lists out all dependencies for a project. However, it returns them in a tree listing.
I would like to get a list of all my dependencies as they are resolved in just a flat list. Similar to how the Maven dependency plugin list
goal behaves.
Here is a short task that meets that need:
task('dependenciesList') << {
println "Compile dependencies"
def selectedDeps = project.configurations.compile.incoming.resolutionResult.allDependencies.collect { dep ->
"${dep.selected}"
}
selectedDeps.unique().sort().each { println it}
}
The third line is the interesting part. You need to get the configuration you care about (compile) then insead of getting dependencies there, the incoming.resolutionResult
will provide the resolved values and versions.
这篇关于如何使用Gradle以扁平形式获取我的项目依赖项列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!