以第3章示例:spmia-chapter3-master中的子項目confsvr為例說明:
其pom文件內容摘要如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
我們使用idea導入該工程,打開該子項目的pom.xml文件,然后右鍵中選擇“show effective pom”,這會打開一個名為“configurationserver-effective-pom.xml”的窗口。
上面的<scope>import</scope>表示將版本為Camden.SR5的依賴spring-cloud-dependencies所對應的pom文件信息導入進來。
所以名為“configurationserver-effective-pom.xml”的窗口中的<dependencyManagement>元素會將pom.xml擴展開來,所以會有很多內容。
我們對名為“configurationserver-effective-pom.xml”的窗口中的<dependencyManagement>元素下的內容和pom.xml中聲明的兩個依賴的最終版本號進行分析:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>1.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
就會發現 <dependencyManagement>不僅用於對子項目的依賴的版本管理,還用於對它自身所在的項目的依賴的版本管理。