【问题标题】:How to override version of libraries included automatically under spring-boot-starter如何覆盖 spring-boot-starter 下自动包含的库版本
【发布时间】:2018-03-27 07:29:06
【问题描述】:

我的 POM 中有 spring-boot-starter,版本由 Camden 依赖管理系统自动解析。

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  <dependencies>    
    <!-- Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
 </dependencies>

这给了我 spring-boot-starter 的 1.4.3.RELEASE 版本。

spring boot starter 自动包含在 maven 依赖项中的 jars 之一是 logback-classic: 1.1.18

ch.qos.logback_logback-core 版本 1.1.8 有一个漏洞,因此我想切换到 logback 版本 1.2 此漏洞在以下链接中进行了说明

https://nvd.nist.gov/vuln/detail/CVE-2017-5929

现在,有没有办法将 logback 版本从 spring-boot-starter 自动解析到的 1.2 覆盖,这样我就不会受到这个漏洞的影响?

【问题讨论】:

  • 视情况而定。如果您使用spring-boot-starter-parent 作为项目的parent,则只需在properties 部分定义您想要的版本,否则将其添加到dependencyManagement 部分以覆盖其他版本集。

标签: spring-boot pom.xml


【解决方案1】:

根据你的pom文件,你可以先排除1.1.8的依赖,再添加1.2.0的依赖。
例如:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.0</version>
</dependency>

【讨论】:

    【解决方案2】:

    像这样在 pom 中添加属性标签

    <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <start-class>org.roshan.Application</start-class>
            <hibernate.version>5.2.10.Final</hibernate.version>
            <liquibase.version>3.5.3</liquibase.version>
            <liquibase-hibernate5.version>3.6.0</liquibase-hibernate5.version>
            <httpcore.version>4.4.5</httpcore.version>
            <httpclient.version>4.5.3</httpclient.version>
            <docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
        </properties>
    

    【讨论】:

    • 我正在使用 Camden 进行依赖管理。我没有使用这样的静态属性
    • 您可以通过添加静态属性覆盖父依赖版本,例如默认休眠可能是 5.2.3,但我将其更改为 5.2.10。测试它,我在我的项目中使用它并且工作正常
    • 问题是我试图覆盖的库版本是 spring-boot-starter 的传递依赖项之一。所以我不确定这样的静态属性是否会覆盖 Camden 解决的此类传递依赖项的版本
    • 你测试了吗?
    猜你喜欢
    • 2021-08-12
    • 2022-01-19
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 2019-08-06
    • 2021-01-12
    • 1970-01-01
    • 2015-09-20
    相关资源
    最近更新 更多