springboot 引用模块不随被引用模块maven版本变化
时间: 2023-07-01 10:17:45 浏览: 66
在 Spring Boot 中,通过 Maven 引入依赖的时候,可以使用 `<dependencyManagement>` 标签来管理依赖的版本。
在父项目的 pom.xml 文件中,可以使用 `<dependencyManagement>` 标签来定义需要使用的依赖版本。这样,子项目只需要引用依赖,而不需要指定版本号,就能够使用父项目中定义的版本。
例如,假设我们的父项目中定义了如下的依赖版本:
```xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
```
那么在子项目中,就可以直接引用 Spring Boot 的依赖,而不需要指定版本号:
```xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
```
这样,无论父项目中的 Spring Boot 版本如何变化,子项目始终使用的是父项目中定义的版本。这种方式可以有效地避免因为版本不一致而导致的兼容性问题。