【问题标题】:Maven transitive dependency problemMaven传递依赖问题
【发布时间】:2011-05-20 16:16:56
【问题描述】:

我有以下设置:

  • Master:有模块 AB
  • A:声明对 BMaster 的依赖作为其父项
  • B: Master 作为它的父节点

所以基本上Master 有一个父pom,它构建AB 其中A 依赖于B

我的问题是我想将所有第 3 方依赖项放在 B 中(例如 JUnit 等)。但是当我这样做时,A 确实可以访问B 声明的依赖项。为什么会这样?我认为 maven 处理传递依赖关系。

这里是我的 poms 的 sn-ps,以防万一:

大师:

<modules>
            <module>../A</module>
            <module>../B</module>
</modules>

答:

<parent>
  <groupId>com.project</groupId>
  <artifactId>Master</artifactId>
  <version>1</version>
  <relativePath>../Master/pom.xml</relativePath>
</parent>
...
<dependency>
 ...
        <artifactId>B</artifactId>
 ...
</dependency>

乙:

<parent>
  <groupId>com.project</groupId>
  <artifactId>Master</artifactId>
  <version>1</version>
  <relativePath>../Master/pom.xml</relativePath>
</parent>
...
<dependency>
 ...
        <artifactId>JUnit</artifactId>
 ...
</dependency>

为什么A 不能访问 JUnit?

【问题讨论】:

    标签: java maven-2 jakarta-ee


    【解决方案1】:

    如果项目 B 中的 JUnit 依赖项具有范围“测试”,那么我认为它不会作为项目 A 中的传递依赖项可见。请参阅 Maven Introduction to the Dependency Mechanism: Dependency Scope 中的表格。

    【讨论】:

      猜你喜欢
      • 2019-01-25
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 2013-02-17
      • 2019-08-23
      • 2019-10-29
      相关资源
      最近更新 更多