io.spring.platform继承方式和import方式更改依赖版本号的问题
2024-08-21 02:19:14
使用io.spring.platform时,它会管理各类经过集成测试的依赖版本号。
但有的时候,我们想使用指定的版本号,这个时候就需要去覆盖io.spring.platform的版本号。
前面的文章总结过,使用io.spring.platform有两种方式,一种是继承,一种是导入。
一、先来看继承的方式:
io.spring.platform使用Brussels-SR7版本
<parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
</parent>
我们想使用阿里的easyexcel框架,2.0.5版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.5</version>
</dependency>
这个时候就出现了依赖问题,easyexcel 2.0.5版本会依赖poi 3.17版本,而io.spring.platform管理的依赖却是3.15版本。
由于依赖都是io.spring.platform管理的,所以打包时会强制使用poi 3.15版本,这会导致代码执行时找不到对应的新版本class,执行失败。
在继承方式使用io.spring.platform时,解决方法也比较简单,覆盖io.spring.platform对poi的版本号管理即可
<properties>
<poi.version>3.17</poi.version>
</properties>
这个时候在来看依赖关系,发现poi的版本引入变成了3.17
这样就解决了问题。
附上完整pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com</groupId>
<artifactId>springboot-dependency7</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>springboot-dependency7</name>
<url>http://maven.apache.org</url> <parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<poi.version>3.17</poi.version>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.springboot_dependency7.main.Applicaiton</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
二、再来看import的方式
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
同样引入easyexcel 2.0.5依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.5</version>
</dependency>
这个时候poi的版本被强制使用3.15
要覆盖io.spring.platform的版本号需要在pom.xml里dependencyManagement节点io.spring.platform引入的前面加上poi的引入
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
再来看poi的依赖
版本已经变成了3.17,解决问题。
附上完整pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com</groupId>
<artifactId>springboot-dependency8</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>springboot-dependency8</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.springboot_dependency8.main.Applicaiton</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
最新文章
- CoreCLR源码探索(一) Object是什么
- ffmpeg-20161003[04,05.06]-bin.7z
- Project Woosah Tu (五色土)
- 刀锋上前行!绕过Ramint蠕虫病毒直接脱壳
- web安全之http协议
- Rserve, java调用R源文件
- HTTP 请求未经客户端身份验证方案“Anonymous”授权。从服务器收到的身份验证标头为“Negotiate,NTLM”
- 解决ajax.net 1.0中文乱码问题!
- HDU 3416 Marriage Match IV (求最短路的条数,最大流)
- 汇编语言中PTR的含义(转载)
- Leaflet实现动态线路
- vs code軟件操作
- poj2352树状数组解决偏序问题
- Mac 上 Charles 抓取 iso http、https数据包
- Magnum Kubernetes源码分析(一)
- mysql查询当前时间,一天内,一周,一个月内的sql语句
- web-day9
- Linux命令之乐--iconv
- #leetcode刷题之路34-在排序数组中查找元素的第一个和最后一个位置
- socket函数send和recv函数