0

我在 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 版本,而依赖项带有显式的不同版本?(即使我降低了弹簧靴版本,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

4

1 回答 1

1

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

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

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

于 2022-01-12T12:34:25.670 回答