Using gradle to find dependency tree

后端 未结 14 1714
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:20

Is it possible to use gradle to produce a tree of what depends on what?

I have a project and would like to find out all the dependencies so I may be able to prune it

14条回答
  •  借酒劲吻你
    2020-11-22 03:22

    If you want all the dependencies in a single file at the end within two steps. Add this to your build.gradle.kts in the root of your project:

    project.rootProject.allprojects {
        apply(plugin="project-report")
    
        this.task("allDependencies", DependencyReportTask::class) {
            evaluationDependsOnChildren()
            this.setRenderer(AsciiDependencyReportRenderer())
        }
    
    }
    

    Then apply:

    ./gradlew allDependencies | grep '\-\-\-' | grep -Po '\w+.*$' | awk -F ' ' '{ print $1 }' | sort | grep -v '\{' | grep -v '\[' | uniq | grep '.\+:.\+:.\+'
    

    This will give you all the dependencies in your project and sub-projects along with all the 3rd party dependencies.

    If you want to get this done in a programmatic way, then you'll need a custom renderer of the dependencies - you can start by extending the AsciiDependencyReportRenderer that prints an ascii graph of the dependencies by default.

提交回复
热议问题