javaspring-bootgradlespring-kafkaspring-kafka-test

Missing dependency on EmbeddedKafka on integration test with groovy and spock


I've been trying to create an integration test using the embeddedKafka, but I'm getting problem of missing dependency when trying to run it, this is the error:

Unable to load class org.springframework.kafka.test.EmbeddedKafkaBroker due to missing dependency org/I0Itec/zkclient/serialize/ZkSerializer

I saw some stuff saying that this is related to my dependencies, so here is my dependencies:

springBootVersion = '2.3.5.RELEASE'

compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.kafka:spring-kafka:${springBootVersion}")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}",
            'org.spockframework:spock-core:1.2-groovy-2.4',
            'org.spockframework:spock-spring:1.2-groovy-2.4',
            'com.microsoft.azure:spring-data-cosmosdb:2.3.0',
            'com.nimbusds:oauth2-oidc-sdk:5.64.4',
    )
testCompile("org.springframework.kafka:spring-kafka-test:${springBootVersion}")

So, my question is, am I missing something?

EDIT

After changed the versions as indicated, I got a different error:

Error creating bean with name 'embeddedKafka': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: scala/math/Ordering$$anon$7

I've added the scala dependencies, but still having the same issue:

testImplementation("org.scala-lang:scala-library:2.12.11")
testImplementation("org.scala-lang:scala-reflect:2.12.11")

Solution

  • You somehow have a mismatched kafka Vs. kafka-clients jars on the classpath; they all must be the same version.

    You generally should not specify a version on boot's dependencies and use its dependency management instead.

    You are pulling in spring-kafka 2.3.5 whereas spring-boot 2.3.5 requires spring-kafka 2.5.7.

    Spring-kafka 2.5.x uses the kafka-clients 2.5.1.

    See here for how to override versions of kafka jars when using a different version to the version that Boot prescribes.