使用io.spring.platform時,它會管理各種通過集成測試的依賴版本號。spring
但有的時候,咱們想使用指定的版本號,這個時候就須要去覆蓋io.spring.platform的版本號。apache
前面的文章總結過,使用io.spring.platform有兩種方式,一種是繼承,一種是導入。springboot
io.spring.platform使用Brussels-SR7版本框架
<parent> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR7</version> </parent>
咱們想使用阿里的easyexcel框架,2.0.5版本maven
<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版本。spring-boot
因爲依賴都是io.spring.platform管理的,因此打包時會強制使用poi 3.15版本,這會致使代碼執行時找不到對應的新版本class,執行失敗。測試
在繼承方式使用io.spring.platform時,解決方法也比較簡單,覆蓋io.spring.platform對poi的版本號管理便可ui
<properties> <poi.version>3.17</poi.version> </properties>
這個時候在來看依賴關係,發現poi的版本引入變成了3.17url
這樣就解決了問題。spa
附上完整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>
<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>