Maven 依赖项大小
Maven dependencies size
我遇到了一个小问题,我在我的项目中添加了下一个依赖项:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
我的项目从 330kb 扩大到 12.1mb 。我知道基于 Apache Http Client 的 HTMLUnit 很重要,但也许 Maven 有一些功能可以排除 libraries/packages 在源代码中没有使用的功能? (非手动排除)
由于这是一个测试依赖项,您可以随时添加 <scope>test</scope>
以防止它被打包到您的构建中。
Maven 怎么知道的?您可能会在运行时使用某种 DI?如果您知道它们未被使用,您当然可以 exclude dependencies ......并且当然可以按照已经提到的目的正确处理依赖关系,如果它仅用于测试,则使用 <scop>test</scope>
。
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
<dependencies>
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>sample.ProjectD</groupId>
<artifactId>Project-D</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
我遇到了一个小问题,我在我的项目中添加了下一个依赖项:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
我的项目从 330kb 扩大到 12.1mb 。我知道基于 Apache Http Client 的 HTMLUnit 很重要,但也许 Maven 有一些功能可以排除 libraries/packages 在源代码中没有使用的功能? (非手动排除)
由于这是一个测试依赖项,您可以随时添加 <scope>test</scope>
以防止它被打包到您的构建中。
Maven 怎么知道的?您可能会在运行时使用某种 DI?如果您知道它们未被使用,您当然可以 exclude dependencies ......并且当然可以按照已经提到的目的正确处理依赖关系,如果它仅用于测试,则使用 <scop>test</scope>
。
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
<dependencies>
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>sample.ProjectD</groupId>
<artifactId>Project-D</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>