How can I get a list of my projects dependencies in a flattened form using Gradle?

℡╲_俬逩灬. 提交于 2019-12-12 07:48:50

问题


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.


回答1:


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.




回答2:


You can flatten the deps tree using sed|sort|uniq in linux or cygwin:

$ gradle dependencies | sed 's/^.* //' | sort | uniq


来源:https://stackoverflow.com/questions/34641631/how-can-i-get-a-list-of-my-projects-dependencies-in-a-flattened-form-using-gradl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!