简体   繁体   中英

How to let maven resolve transitive dependency for local dependency

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM