在 Spring 中覆盖 Kafka 版本的某些依赖项引导失败

Overwrite of Kafka Version in Spring Boot fails for some dependencies

我有一个新的 Spring Boot 2.6.3 Java 11 应用程序,带有 Spring Kafka 依赖项(由 start.spring.io 生成)。

默认使用 Kafka 3.0.0。我想把Kafka版本改成3.1.0,加入

<kafka.version>3.1.0</kafka.version>

到 属性 部分。大多数 Kafka 库现在在 3.1.0 版本中已解决,但不是全部(最重要的是,测试范围内的依赖项未正确解决):

$ mvn dependency:resolve | grep kafka
[INFO] -------------------< com.example:spring-kafka-demo >--------------------
[INFO] Building spring-kafka-demo 0.0.1-SNAPSHOT
[INFO] --- maven-dependency-plugin:3.2.0:resolve (default-cli) @ spring-kafka-demo ---
[INFO] Can't extract module name from kafka_2.13-3.1.0.jar: kafka.2.13: Invalid module name: '2' is not a Java identifier
[INFO] Can't extract module name from kafka_2.13-3.0.0-test.jar: kafka.2.13: Invalid module name: '2' is not a Java identifier
[INFO]    org.springframework.kafka:spring-kafka:jar:2.8.2:compile -- module spring.kafka [auto]
[INFO]    org.apache.kafka:kafka-clients:jar:3.1.0:compile -- module kafka.clients (auto)
[INFO]    org.springframework.kafka:spring-kafka-test:jar:2.8.2:test -- module spring.kafka.test [auto]
[INFO]    org.apache.kafka:kafka-clients:jar:test:3.0.0:test -- module kafka.clients (auto)
[INFO]    org.apache.kafka:kafka-metadata:jar:3.1.0:test -- module kafka.metadata (auto)
[INFO]    org.apache.kafka:kafka-server-common:jar:3.1.0:test -- module kafka.server.common (auto)
[INFO]    org.apache.kafka:kafka-raft:jar:3.1.0:test -- module kafka.raft (auto)
[INFO]    org.apache.kafka:kafka-streams-test-utils:jar:3.1.0:test -- module kafka.streams.test.utils (auto)
[INFO]    org.apache.kafka:kafka-streams:jar:3.1.0:test -- module kafka.streams (auto)
[INFO]    org.apache.kafka:kafka_2.13:jar:3.1.0:test
[INFO]    org.apache.kafka:kafka-storage:jar:3.1.0:test -- module kafka.storage (auto)
[INFO]    org.apache.kafka:kafka-storage-api:jar:3.1.0:test -- module kafka.storage.api (auto)
[INFO]    org.apache.kafka:kafka_2.13:jar:test:3.0.0:test

开头的错误信息很有趣。它可能与此有关吗?是 Kafka 而不是 Spring 启动问题?


这是 pom 文件

<?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 https://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.6.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-kafka-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-kafka-demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
        <kafka.version>3.1.0</kafka.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

根据docs section on overriding dependencies

您可以手动添加它要查找的那个

    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_2.13</artifactId>
        <classifier>test</classifier>
        <scope>test</scope>
        <version>${kafka.version}</version>
    </dependency>