Maven的模块化管理中的版本锁定

97 阅读1分钟

配置模块继承后

在此时,我们会在父类里统一配置各个子类的依赖的版本

这样做可以统一各子类的依赖版本,不仅避免了版本冲突,并且避免升级依赖的时候要在子类里一个一个修改

jjwt为例子,在父类的pom里我们通过在<properties>里定义它的版本号和引用名称<jjwt.version>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <jjwt.version>0.9.1</jjwt.version>
</properties>

这样就可以运用<dependencyManagement>来控制所有子类的jjwt版本,在<version>里填入在<properties>里定义好的<jjwt.version>来让版本锁定生效

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt</artifactId>
      <version>${jjwt.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

在此之后我们在子类的pom里添加依赖的时候只需要输入

<dependencies>
 <dependency>
  <groupId>io.jsonwebtoken</groupId>
  <artifactId>jjwt</artifactId>
 </dependency>
</dependencies>

就可以成功添加jjwt依赖

使用<dependencyManagement>标签只会锁定依赖版本,不会产生真正的依赖

<dependencies>会产生