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

前端 未结 4 2048
花落未央
花落未央 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:40

    I keep the a small pom.xml template on my workstation to identify heavy-weight dependencies.

    Assuming you want to see the weight of org.eclipse.jetty:jetty-client with all of its transitives create this in a new folder.

    
      4.0.0
      not-used
      fat
      standalone
    
      
        
          org.eclipse.jetty
          jetty-client
          LATEST
        
      
      
        
          
            maven-shade-plugin
            
              
               package
               
                  shade
               
              
            
          
        
      
    
    

    Then cd to the folder and run mvn package and check the size of the generated fat jar. On Unix-like systems you can use du -h target/fat-standalone.jar for that.

    In order to test another maven artifact just change groupId:artifactId in the above template.

提交回复
热议问题