【maven】依赖 及 问题排查

maven负责管理工程依赖的二进制的jar包。这些jar包可能编译时需要可能运行时需要。
依赖会形成不同的分支,分支与分支之间没有关系。比如两个分支都依赖了jar包A,那么这其实是两个A,版本都可能不同,具体用哪个版本取决于maven内部机制。比如最短路径。
有时候jar包缺失不会影响编译,是因为本工程的源码没有直接依赖这个jar包,而是依赖的其他jar包会依赖这个jar包,这种情况编译没有问题,但是运行时会报java.lang.ClassNotFoundException异常。

关于maven依赖中相同jar包的多版本问题:

Maven way of resolving dependency conflicts :
Maven works on the principle of nearest wins strategy while resolving the dependency conflicts, that   means whichever version it finds nearer in the tree, it will take that version and ignore the other versions. Actually I should say Maven is little bit lazy type of guy , so whenever it starts looking for a dependency it starts traversing the tree from the root and whichever version it found earlier , it will select that and returns from their without going further . If it goes further their might be a chance that it can find some newer version but as it returns from there and take the older version with it to resolve the dependencies L . Honestly speaking it is not a fault of maven because he wants to finish the job as soon as possible and have some rest. Most importantly he(maven) doesn’t know which version your application is expecting so Maven will say to you , Hey , it is yours responsibility to let me know which version you want and if you don’t tell me I will work my own way i.e. nearer the better.

具体用哪个由maven决定,即maven先搜到哪个就用哪个,不过具体maven的搜索算法还没搞清,比如深度?广度?

不过可以不用探究那么深,要明白的是这个问题怎么解决?exclude一条依赖路径即可。

参考:http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值