pom.xml配置文件中的dependencies與dependencyManagement有什麼區別?在使用上有什麼注意要點呢?測試
dependencyManagement主要用來控制全部子項目依賴的版本號。code
爲了項目的正確運行,必須讓全部的子項目使用依賴項的統一版本,必須確保應用的各個項目的依賴項和版本一致,才能保證測試的和發佈的是相同的結果。xml
dependencyManagement中依賴的版本號,是當前全部子項目依賴的默認版本號。ci
若是dependencies與dependencyManagement中的依賴版本號不一樣,則選用dependencies的依賴版本號。io
若是dependencyManagement中有不少依賴,在修改某一個依賴的版本號時會產生查找不便的問題。class
可使用<properties></properties>以變量的形式將版本號彙集在一塊兒,便於後續維護。變量
1. <properties> 2. <commons.httpclient>3.1</commons.httpclient> 3. </properties> 5. <dependencies> 6. <!--httpclient--> 7. <dependency> 8. <groupId>commons-httpclient</groupId> 9. <artifactId>commons-httpclient</artifactId> 10. </dependency> 11. </dependencies> 13. <dependencyManagement> 14. <!--httpclient--> 15. <dependency> 16. <groupId>commons-httpclient</groupId> 17. <artifactId>commons-httpclient</artifactId> 18. <version>${commons.httpclient}</version> 19. </dependency> 20. </dependencyManagement>