Maven/Gradle way to calculate the total size of a dependency with all its transitive dependencies included

前端 未结 4 2091
花落未央
花落未央 2021-02-07 06:05

I would like to be able to perform an analysis on each of my project POMs to determine how many bytes each direct dependency introduces to the resulting package based on the sum

4条回答
  •  自闭症患者
    2021-02-07 06:30

    If you have a configuration which includes all the necessary dependencies that you wish to calculate the size for you can simply put the following snippet in your build.gradle file:

    def size = 0
    configurations.myConfiguration.files.each { file ->
        size += file.size()
    }
    println "Dependencies size: $size bytes"
    

    This should print out when you run any gradle task after the build file is compiled.

提交回复
热议问题