3.1-1 dependencyManagement中的type为pom用法

 
以第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>不仅用于对子项目的依赖的版本管理,还用于对它自身所在的项目的依赖的版本管理。
 

猜你喜欢

转载自www.cnblogs.com/mongotea/p/11973195.html
3.1
今日推荐