问题
pom.xml配置文件中的dependencies与dependencyManagement有什么区别?在应用上有什么留神要点呢?
解决
dependencyManagement次要用来管制所有子项目依赖的版本号。
为了我的项目的正确运行,必须让所有的子项目应用依赖项的对立版本,必须确保利用的各个我的项目的依赖项和版本统一,能力保障测试的和公布的是雷同的后果。
dependencyManagement中依赖的版本号,是以后所有子项目依赖的默认版本号。
如果dependencies与dependencyManagement中的依赖版本号不同,则选用dependencies的依赖版本号。
扩大
如果dependencyManagement中有很多依赖,在批改某一个依赖的版本号时会产生查找不便的问题。
能够应用<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>