Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: scala/math/Ordering with spring-kafka-test 2.5.7

I have a small library that provides a JUnit 5 extension around EmbeddedKafkaBroker, which tries to be more performant than just using @DirtiesContext by instead resetting the offsets to latest between tests instead of throwing away the whole context.

My build.gradle is:

import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE' apply false
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}

dependencyManagement {
    imports {
        mavenBom SpringBootPlugin.BOM_COORDINATES
    }
}

sourceCompatibility = '1.8'

dependencies {
    implementation 'org.junit.jupiter:junit-jupiter-api'
    implementation 'org.springframework.kafka:spring-kafka'
    implementation 'org.springframework.kafka:spring-kafka-test'
    compileOnly 'org.springframework.integration:spring-integration-core'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntime 'org.springframework.integration:spring-integration-core'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine'
}

This resolves to using spring-kafka:2.5.7 and various Scala libraries at 2.12. When extension tries to start the EmbeddedKafkaBroker, I get the following exception:

java.lang.NoClassDefFoundError: scala/math/Ordering$$anon$7

    at kafka.api.ApiVersion$.orderingByVersion(ApiVersion.scala:45)
    at kafka.api.ApiVersion.compare(ApiVersion.scala:139)
    at kafka.api.ApiVersion.compare$(ApiVersion.scala:138)
    at kafka.api.KAFKA_2_5_IV0$.compare(ApiVersion.scala:339)
    at kafka.api.KAFKA_2_5_IV0$.compare(ApiVersion.scala:339)
    at scala.math.Ordered.$greater$eq(Ordered.scala:91)
    at scala.math.Ordered.$greater$eq$(Ordered.scala:91)
    at kafka.api.KAFKA_2_5_IV0$.$greater$eq(ApiVersion.scala:339)
    at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:1561)
    at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:1269)
    at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:313)

The searching I've done so far has only turned up issues with overriding particular kafka or scala versions, which I am not doing. Any ideas what I'm missing, or how to fix it?

like image 525
mrusinak Avatar asked Dec 13 '22 07:12

mrusinak


1 Answers

I have the same issue here. I looked into the spring-kafka 2.5.7.RELEASE which is the one used by Spring Boot 2.3.5 and added same scala dependency to my project as a workaround to my build.gradle:

dependencies {
    ...
    testImplementation("org.scala-lang:scala-library:2.12.11")
}

This solved my problem for the moment. Hope it will get fixed in next spring-kafka version.

like image 183
Vitali Avatar answered Dec 15 '22 21:12

Vitali