ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

io.spring.platform继承方式和import方式更改依赖版本号的问题

2019-11-08 09:55:59  阅读:269  来源: 互联网

标签:版本号 spring 3.17 platform io poi org


使用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>

 

标签:版本号,spring,3.17,platform,io,poi,org
来源: https://www.cnblogs.com/ld-mars/p/11818252.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有