可以使用 Maven 的 Dependency Management 来控制依赖的版本号。在父 POM 中使用 dependencyManagement 标签声明依赖版本号,然后在子 POM 中引入依赖,不需要指定版本号,Maven 会自动使用父 POM 中声明的版本号。

例如,在父 POM 中声明了以下依赖版本号:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>

然后在子 POM 中引入依赖,不需要指定版本号:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

这样就可以保证依赖的版本号与父 POM 中声明的版本号一致,而且可以方便地统一升级版本号。如果需要使用本地的版本号,只需要在父 POM 中声明本地版本号即可

SpringBoot pom 引入依赖已本地版本为主版本

原文地址: https://www.cveoy.top/t/topic/friQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录