Issue
I have a fresh Spring Boot 2.6.3 Java 11 application with a Spring Kafka Dependency (generated with href="https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.6.3&packaging=jar&jvmVersion=11&groupId=com.example&artifactId=spring-kafka-demo&name=spring-kafka-demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.spring-kafka-demo&dependencies=kafka" rel="nofollow noreferrer">start.spring.io).
By default Kafka 3.0.0 is is used. I want to change the Kafka version to 3.1.0 and added
<kafka.version>3.1.0</kafka.version>
to the property section. The most Kafka libs are resolved in version 3.1.0 now, but not all (above all, dependencies in the test scope are not correctly resolved):
$ 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
The error messages at the beginning are interesting. Does it perhaps have something to do with that? Is it a Kafka rather than a Spring Boot problem?
This is the pom file
<?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>
Solution
According to the docs section on overriding dependencies
You could manually add the one it's looking for
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<version>${kafka.version}</version>
</dependency>
Answered By - OneCricketeer
Answer Checked By - Willingham (JavaFixing Volunteer)