顶层 pom 中的 dependencies 与 dependencyManagement 区别
作者:Yan
頂層?pom?中的?dependencies?與?dependencyManagement?中的?dependencies?元素有一個(gè)重要的區(qū)別:
dependencyManagement?中的?dependencies?元素只表明依賴項(xiàng)版本的優(yōu)先選擇,并不影響項(xiàng)目的依賴項(xiàng);而?dependencies?元素則影響項(xiàng)目的依賴項(xiàng)。
只有在子項(xiàng)目的dependencies?元素中沒有指明版本信息時(shí),?dependencyManagement?中的dependencies?元素才起作用。
dependencies 和 dependencyManagement 的區(qū)別在于:
前者,即使在子項(xiàng)目中不寫該依賴項(xiàng),那么子項(xiàng)目仍然會(huì)從父項(xiàng)目中繼承該依賴項(xiàng)。
后者,如果在子項(xiàng)目中不寫該依賴項(xiàng),那么子項(xiàng)目中是不會(huì)從父項(xiàng)目繼承該依賴項(xiàng)的;只有在子項(xiàng)目中寫了該依賴項(xiàng),才會(huì)從父項(xiàng)目中繼承該項(xiàng),并且version 和 scope 都讀取自 父pom。
兩者是結(jié)合起來用互補(bǔ):dependencies用來繼承,具有依賴傳遞性;dependencyManagement用來統(tǒng)一管理依賴版本,不具有依賴傳遞性!
總結(jié)
以上是生活随笔為你收集整理的顶层 pom 中的 dependencies 与 dependencyManagement 区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: maven-compiler-plugi
- 下一篇: java集合排序