问题描述
我们有一个项目A,它取决于依赖图书馆C的项目B.A和B是本地项目,而C是maven中央库的公共图书馆。
pom.xml for A:
< name> ProjA / name>
...
<依赖关系>
< groupId> com.abc< / groupId>
< artifactId> ProjB< / artifactId>
< version> 1.0< / version>
< / dependency>
pom.xml for B:
<名称> ProjB /名称>
...
<依赖关系>
< groupId> org.apache.maven< / groupId>
< artifactId> C< / artifactId>
< version> 2.23.2< / version>
< / dependency>
运行 mvn依赖关系:tree -Dverbose
在A中,它不解决B的依赖性,并且B中使用的这些依赖关系也不在A的Maven Dependencies中显示。这是很好的编译,但是由于NoClassDefFound错误,在运行时会失败。
[INFO]扫描项目...
有没有办法让maven解决问题我们认为这里的问题是B不存在于本地的回购中。$(
[INFO]
[INFO] -------------------------------------- ----------------------------------
[INFO] Building ProjA 1.0
[INFO ] ------------------------------------------------- -----------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree默认-cli)@ ProjA ---
[INFO] com.abc.projA:jar:1.0
[INFO] + - com.abc.projB:jar:1.0:compile
[信息] ------------------------------------------------ ------------------------
[INFO] BUILD SUCCESS
[INFO] ---------- -------------------------------------------------- ------------
[INFO]总时间:2.326 s
[INFO]完成于:2016-09-15T16:29:49-07:00
[INFO] Final Memory:13M / 309M
[INFO] --------------------------------- ---------------------------------------
解决方案c $ c> .m2
您需要为B运行
mvn install
将软件包安装到本地可以由A提取的.m2
中。
然后运行
mvn依赖关系:树中的Dverbose
不会导致问题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这篇关于如何让maven解决本地依赖的传递依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!