【问题标题】:Spring boot starter dependency overwrites netty version of the qpid-jms-clientSpring boot 启动器依赖覆盖了 qpid-jms-client 的 netty 版本
【发布时间】:2021-11-26 10:14:18
【问题描述】:

我在 Spring Boot 项目中使用 QPID-JMS-Client(版本 0.59.0)。我想覆盖 netty 版本,因为这个版本的 QPID 带有 netty 版本:4.1.63.Final [1]。我想将netty版本覆盖到最新的:4.1.68.Final。 我还在我的 POM 中使用 spring-boot-starter-parent(版本:2.3.12.RELEASE)作为父 pom,它还附带一个 netty 版本(4.1.65.Final)。我知道 Spring Boot 版本相当旧,应该更新。无论如何,似乎 spring-boot-starter-parent 强制执行其 netty 版本。

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>org.example</groupId>
    <artifactId>untitled1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.qpid/qpid-jms-client -->
        <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-jms-client</artifactId>
            <version>0.59.0</version>
        </dependency>
    </dependencies>
</project>

由于我没有使用任何 spring boot 依赖项,我不明白为什么 netty 版本设置为4.1.65.Final

[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ untitled1 ---
[INFO] org.example:untitled1:jar:1.0-SNAPSHOT
[INFO] \- org.apache.qpid:qpid-jms-client:jar:0.59.0:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO]    +- org.apache.geronimo.specs:geronimo-jms_2.0_spec:jar:1.0-alpha-2:compile
[INFO]    +- org.apache.qpid:proton-j:jar:0.33.8:compile
[INFO]    +- io.netty:netty-buffer:jar:4.1.65.Final:compile
[INFO]    +- io.netty:netty-common:jar:4.1.65.Final:compile
[INFO]    +- io.netty:netty-handler:jar:4.1.65.Final:compile
[INFO]    |  +- io.netty:netty-resolver:jar:4.1.65.Final:compile
[INFO]    |  \- io.netty:netty-codec:jar:4.1.65.Final:compile
[INFO]    +- io.netty:netty-transport:jar:4.1.65.Final:compile
[INFO]    +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.65.Final:compile
[INFO]    |  \- io.netty:netty-transport-native-unix-common:jar:4.1.65.Final:compile
[INFO]    +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.65.Final:compile
[INFO]    \- io.netty:netty-codec-http:jar:4.1.65.Final:compile

QPID-JMS-CLIENT 的 pom 通过属性 netty-version[3] 定义 netty 版本,而 spring boot 使用 netty.version。如果我覆盖了spring boot的属性,QPID的版本就会改变:

...
<properties>
    <netty.version>4.1.68.Final</netty.version>
</properties> 
...

如果我覆盖 QPID 的版本,则完全没有效果:

...
<properties>
    <netty-version>4.1.68.Final</netty-version>
</properties> 
...

所以我的问题是:

  • 为什么 maven 强制执行父 poms netty 版本,而依赖项带有明确的不同版本? (即使我降低了 spring boots 版本,netty 依赖项也设置为该版本)
  • 如何正确覆盖netty的版本?

问候

[1]https://mvnrepository.com/artifact/org.apache.qpid/qpid-jms-client/0.59.0

[2]https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.3.12.RELEASE

[3]https://github.com/apache/qpid-jms/blob/main/pom.xml#L40

【问题讨论】:

  • 使用更新版本的 Spring Boot(例如 2.5.5)..
  • 当然,这是可能的,但我想了解为什么 maven 的行为如此。

标签: java spring-boot maven qpid spring-boot-starter-parent


【解决方案1】:

您的 pom 将从您在其父层次结构中使用的 spring pom 继承 dependencyManagement 部分。该祖先包括管​​理 netty 版本的 spring-boot-dependencies(您似乎已经意识到,使用 netty.version 属性导入 netty-bom)。

因此,有效 pom(可通过mvn help:effective-pom 查看)中的dependencyManagement 将管理所选的netty 版本。客户端 pom 指定的 netty 版本与您的应用程序使用的内容无关,因为该版本实际上已被您的构建覆盖和管理。这是依赖管理配置的关键用途之一。

如果你想在本地覆盖 netty 的版本同时拥有父层次结构,你可以使用与从父继承的 dependencyMangement 相关的 netty.version 属性,正如你已经注意到的,或者你可以定义自己的本地 dependencyMangement对于你的 pom 中的 netty,它会覆盖它的继承父管理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-29
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多