How can I get a list of my projects dependencies i

2020-06-14 05:47发布

问题:

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