Maven/Gradle方法来计算包含所有传递依赖项的依赖项总大小 [英] Maven/Gradle way to calculate the total size of a dependency with all its transitive dependencies included

查看:170
本文介绍了Maven/Gradle方法来计算包含所有传递依赖项的依赖项总大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够对我的每个项目POM进行分析,以基于每个传递依赖项的所有传递依赖项之和来确定每个直接依赖项将多少字节引入结果包中.

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 of all of its transitive dependencies.

例如,如果依赖项A引入了B,C和D,我希望能够看到一个摘要,显示A->总大小=(A + B + C + D).

For example, if dependency A brings in B, C, and D, I would like to be able to see a summary showing A -> total size = (A + B + C + D).

是否存在确定这些信息的现有Maven或Gradle方法?

Is there an existing Maven or Gradle way to determine this information?

推荐答案

我在工作站上保留了一个小的pom.xml模板,以标识重量级依赖项.

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

假设您要查看 org.eclipse.jetty:jetty-client 的权重及其所有传递对象,请在新文件夹中创建它.

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

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>not-used</groupId>
  <artifactId>fat</artifactId>
  <version>standalone</version>

  <dependencies>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-client</artifactId>
      <version>LATEST</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
           <phase>package</phase>
           <goals>
              <goal>shade</goal>
           </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

然后cd到文件夹并运行mvn package并检查生成的胖子罐的大小.在类似Unix的系统上,您可以使用du -h target/fat-standalone.jar.

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.

要测试另一个Maven工件,只需在上述模板中更改groupId:artifactId.

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

这篇关于Maven/Gradle方法来计算包含所有传递依赖项的依赖项总大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆