Appendix A: Override Spring Boot Dependencies
When using Spring for Apache Kafka in a Spring Boot application, the Apache Kafka dependency versions are determined by Spring Boot’s dependency management.
If you wish to use a different version of kafka-clients
or kafka-streams
, and use the embedded kafka broker for testing, you need to override their version used by Spring Boot dependency management; set the kafka.version
property.
Or, to use a different Spring for Apache Kafka version with a supported Spring Boot version, set the spring-kafka.version
property.
Or, to use a different Spring for Apache Kafka version with a supported Spring Boot version, set the spring-kafka.version
property.
For example, 2.9.13 is supported by Spring Boot 2.7.x which brings in 2.8.x by default.
<properties>
<kafka.version>3.6.0</kafka.version>
<spring-kafka.version>2.9.13</spring-kafka.version>
</properties>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- optional - only needed when using kafka-streams -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Required for the embedded broker when using 3.6.0 or later with Boot 2.7.x -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-server-common</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<version>${kafka.version}</version>
</dependency>
ext['kafka.version'] = '3.6.0'
ext['spring-kafka.version'] = '2.9.13'
dependencies {
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.apache.kafka:kafka-streams' // optional - only needed when using kafka-streams
testImplementation 'org.springframework.kafka:spring-kafka-test'
// the following is required for the embedded broker when using 3.6.0 or later with Boot 2.7.x
testImplementation "org.apache.kafka:kafka-server-common:$kafka.version:test"
}
The test scope dependencies are only needed if you are using the embedded Kafka broker in tests.