【问题标题】:Maven pom file inheritance of scopeMaven pom文件继承范围
【发布时间】:2018-10-09 14:16:16
【问题描述】:

我在父 pom 中有以下定义:

<dependency>
  <groupId>net.sourceforge.htmlunit</groupId> 
  <artifactId>htmlunit</artifactId> 
  <version>2.11</version> 
  <scope>test</scope>      
</dependency>

然后在我的孩子 pom 中:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
</dependency>

我发现当我的 WAR 文件(我的子 pom 中的打包类型)构建时,来自 htmlunit 的传递依赖项包含在 WEB-INF/lib 目录中(特别是 commons-codec)。

我会认为,因为依赖项的范围是“测试”,所以它和它的任何传递依赖项都不应该被打包。我的假设不正确吗?

【问题讨论】:

    标签: java maven


    【解决方案1】:

    你的假设是错误的。由于您提供了范围test,因此此 jar 将同时出现在测试和执行阶段。

    范围应该是provided。范围 provided 将使 jar 在编译和测试类路径中可用,并且不可传递。

    详情请参阅http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.htmldependency scope section

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 2020-12-28
      • 2012-03-17
      • 2019-06-07
      • 2011-11-26
      • 2016-09-18
      • 2012-12-22
      • 2013-09-28
      • 2016-04-11
      相关资源
      最近更新 更多