springboot springweb

Maven 中 dependencyManagement 标签使

2018-01-23  本文已影响3883人  当当一丢丢

一句话解释

业务场景

项目中依赖包版本号判断途径

单一模块情况下 pom.xml

//只是对版本号进行管理,不会实际引入jar  
<dependencyManagement>  
      <dependencies>  
            <dependency>  
                <groupId>org.springframework</groupId> //jar 包身份限定  
                <artifactId>spring-core</artifactId>  
                <version>3.2.7</version>  //版本号的声明
            </dependency>  
    </dependencies>  
</dependencyManagement>  
  
//会实际下载jar包  
<dependencies>  
       <dependency>  
                <groupId>org.springframework</groupId>  
                <artifactId>spring-core</artifactId> //不声明version 标签,则会继承
       </dependency>  
</dependencies>

多模块情况:
parent-module 顶层模块,son1-module 和 son2-module 并列继承 parent-module

parent-module 中 pom.xml

<properties>
    // 集中在properties 标签中定义所有 依赖的版本号
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <org.eclipse.persistence.jpa.version>1.2.6</org.eclipse.persistence.jpa.version>
    <developer.organization>xxx</developer.organization>
    <javaee-api.version>1.8</javaee-api.version>
</properties>

<dependencyManagement>  
    //定义公共依赖的版本号
    <dependencies> 
        <dependency>  
            <groupId>org.eclipse.persistence</groupId>  
            <artifactId>org.eclipse.persistence.jpa</artifactId>  
            <version>${org.eclipse.persistence.jpa.version}</version>  
            <scope>provided</scope>  
        </dependency>  
          
        <dependency>  
            <groupId>javax</groupId>  
            <artifactId>javaee-api</artifactId>  
            <version>${javaee-api.version}</version>  
        </dependency>  
    </dependencies>  
</dependencyManagement> 
son-module1 中 的 pom.xml
<!--继承父类-->  
<parent>  
    <artifactId>parent-module</artifactId> //声明父类的身份信息
    <groupId>com.ppd</groupId>  
    <version>0.0.1-SNAPSHOT</version>  
    <relativePath>../parent-module/pom.xml</relativePath> //声明父类的pom 文件路径
</parent>  

<modelVersion>4.0.0</modelVersion>  
<artifactId>son-module</artifactId>  
<packaging>ejb</packaging>  
  
<!--依赖关系-->  
<dependencies>  
    <dependency>  
        <groupId>javax</groupId>  
        <artifactId>javaee-api</artifactId> //继承父类
    </dependency>  
      
    <dependency>  
        <groupId>com.fasterxml.jackson.core</groupId>  
        <artifactId>jackson-annotations</artifactId>  //继承父类
    </dependency>  
      
    <dependency>  
        <groupId>org.eclipse.persistence</groupId>  
        <artifactId>org.eclipse.persistence.jpa</artifactId>  //继承父类
        <scope>provided</scope>  
    </dependency>  
</dependencies> 

与 dependencies 标签下 dependency 的区别

参考:http://blog.csdn.net/liutengteng130/article/details/46991829
参考:https://www.cnblogs.com/mr-wuxiansheng/p/6189438.html
上一篇下一篇

猜你喜欢

热点阅读