关于java:Maven-dependencies与dependencyManagement的区别

2次阅读

共计 876 个字符,预计需要花费 3 分钟才能阅读完成。

问题

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>
正文完
 0