When trying to use @EmbeddedKafka
from spring-kafka-test
, I end up with ClassNotFoundException: scala.collection.convert.AsJavaExtensions
(full stack trace here) when running the test.
I've tried a different Kafka version (org.apache.kafka:kafka_2.11:2.4.1
instead of org.apache.kafka:kafka_2.12:2.8.0
) and also different versionf of org.scala-lang:scala-library
(2.13.6
, 2.12.10
, 2.11.12
, 2.10.6
).
What do I need to do in order to fix this?
Below is a minimal example to reproduce the problem:
src/main/kotlin/com/acme/Application.kt
package com.acme
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
src/test/kotlin/com/acme/integration/TestFullStack.kt
package com.acme.integration
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.kafka.test.context.EmbeddedKafka
import org.springframework.test.context.junit.jupiter.SpringExtension
@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EmbeddedKafka(topics = ["testtopic"], controlledShutdown = true)
class TestFullStack {
@Test
fun `test init`() {
}
}
build.gradle.kts
plugins {
id("org.springframework.boot") version "2.5.4"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.21"
kotlin("plugin.spring") version "1.5.21"
}
group = "com.acme"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation(group = "org.apache.kafka", name = "kafka_2.12", version = "2.8.0")
implementation(group = "org.scala-lang", name = "scala-library", version = "2.12.10")
implementation(group = "org.springframework.kafka", name = "spring-kafka", version = "2.7.6")
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
implementation(group = "org.jetbrains.kotlin", name = "kotlin-reflect")
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
testImplementation(group = "org.springframework.kafka", name = "spring-kafka-test", version = "2.7.6")
testImplementation(group = "org.testcontainers", name = "kafka", version = "1.16.0")
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-test-junit")
}
tasks {
withType<Test> {
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
useJUnitPlatform()
}
}
settings.gradle.kts
rootProject.name = "acmetest"
Dockerfile
FROM openjdk:11-jdk-slim
WORKDIR /home/test
ADD . /home/test
RUN ./gradlew test
CodePudding user response:
Made it work by using the correct dependencies.
dependencies {
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web")
implementation(group = "org.apache.kafka", name = "kafka_2.13")
implementation(group = "org.apache.kafka", name = "kafka-clients")
testImplementation(group = "org.springframework.boot", name = "spring-boot-starter-test")
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-test-junit")
testImplementation(group = "org.springframework.kafka", name = "spring-kafka-test")
}