开发者

Maven transitive dependency problem

I have the following setup:

  • Master: has modules A and B
  • A: declares a dependency on B, Master as its parent
  • B: Master as its parent

So basically Master has a parent pom which builds A and B where A has a dependency on B.

My problem is that I want to put all of the 3rd party dependencies in B (things like JUnit etc.). But when I do this, A does have access to the depende开发者_高级运维ncies declared by B. Why is this happening? I thought maven handles transitive dependencies.

Here are snippets of my poms just in case:

Master:

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

A:

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

B:

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

Why doesn't A have access to JUnit?


If the JUnit dependency in Project B has scope 'test' then I don't believe it will be visibile as a transitive dependency in Project A. See the table in Maven Introduction to the Dependency Mechanism: Dependency Scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜