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/
标签:Maven,依赖,dependency,jar,maven,排查,version From: https://blog.51cto.com/u_15873544/5844585