zoukankan      html  css  js  c++  java
  • io.spring.platform继承方式和import方式更改依赖版本号的问题

    使用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>
  • 相关阅读:
    【题解】CF#983 E-NN country
    【题解】CF#403 D-Beautiful Pairs of Numbers
    【题解】CF#285 E-Positions in Permutations
    【题解】FJOI2015火星商店问题
    【题解】Atcoder AGC#01 E-BBQ Hard
    【题解】Atcoder AGC#03 E-Sequential operations on Sequence
    【题解】CF#280 C-Game on Tree
    【题解】CF#833 B-The Bakery
    [BZOJ3600] 没有人的算术 [重量平衡树+权值线段树]
    [bzoj3514][CodeChef GERALD07] Chef ans Graph Queries [LCT+主席树]
  • 原文地址:https://www.cnblogs.com/ld-mars/p/11818252.html
Copyright © 2011-2022 走看看