Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 692
checketts Avatar asked Jan 06 '16 19:01

checketts


2 Answers

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

$ gradle dependencies | sed 's/^.* //' | sort | uniq
like image 88
smuk Avatar answered Oct 13 '22 00:10

smuk


Thanks for the answers already supplied.

Finally I complete it by a more standard way:

project.gradle.addListener(new DependencyResolutionListener() {
    
    @Override
    void beforeResolve(ResolvableDependencies dependencies) {}
    
    @Override
    void afterResolve(ResolvableDependencies dependencies) {
        dependencies.resolutionResult.allComponents.each { select ->
            println "selected component: ${select} " + select.selectionReason
        }
    }
})

Project implementation will also be resolved in this way, and the final selected component version will be resolved correctly.

like image 39
lirui Avatar answered Oct 13 '22 00:10

lirui