How to let maven resolve transitive dependency for

2019-07-31 14:30发布

We have a project A which depends on project B which depends on library C. A and B are local projects while C is a public library in maven central repo.

pom.xml for A:

<name>ProjA/name>
...
<dependency>
  <groupId>com.abc</groupId>
  <artifactId>ProjB</artifactId>
  <version>1.0</version>
</dependency>

pom.xml for B:

<name>ProjB/name>
...
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>C</artifactId>
    <version>2.23.2</version>
</dependency>

When run mvn dependency:tree -Dverbose in A, it does not resolve the dependencies of B and such dependencies used in B is not shown in A's Maven Dependencies as well. This is fine for compilation but will fail in runtime because of NoClassDefFound error.

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ProjA 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ ProjA ---
[INFO] com.abc.projA:jar:1.0
[INFO] +- com.abc.projB:jar:1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.326 s
[INFO] Finished at: 2016-09-15T16:29:49-07:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------

Is there any way to let maven resolve transitive dependency for such local dependency as B?

1条回答
相关推荐>>
2楼-- · 2019-07-31 15:18

I think the problem here is B does not exist in the local repo .m2

You need to run mvn install for B, to install the package into .m2 which can be picked up by A locally.

Then running mvn dependency:tree -Dverbose in A won't cause problem

查看更多
登录 后发表回答