I want to use Kafka for JUnit, so I added this dependency:
<dependency>
<groupId>net.mguenther.kafka</groupId>
<artifactId>kafka-junit</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
Locally it works well. But on Jenkins I get an error:
java.lang.NoClassDefFound scala/math/Ordering
If I add scala-library
dependency (version 2.1.12
), I get:
java.lang.NoClassDefFound com.typesafe.scalalogging.Logger$
Also, I have several Apache Beam
dependencies with 2.9.0
version.
What can I check to solve this issue?
UPD:
If I add this dependency:
<dependency>
<groupId>com.github.charithe</groupId>
<artifactId>kafka-junit</artifactId>
<version>${kafkaJunit.version}</version>
</dependency>
I get:
java.lang.NoClassDefFoundError: scala/MatchError
If I add scala-library
(version 2.1.12
), I get:
java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)[Ljava/lang/Object;
And with the last version, I get:
java.lang.NoClassDefFound com.typesafe.scalalogging.Logger$
UPD
I got an exception using Kafka for JUnit as @AntonLitvinenko suggested. My question about it here.
I added this dependency to fix it (see the issue):
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>2.12.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
Also, I used 2.0.1
version for kafka-junit and kafka_2.11:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>${kafkaVersion}</version>
<scope>test</scope>
</dependency>
OLD
I decided to use another Kafka-JUnit library by Salesforce. I added this group of dependencies:
<!-- Declare kafka-junit4 dependency -->
<dependency>
<groupId>com.salesforce.kafka.test</groupId>
<artifactId>kafka-junit4</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<!-- Include Kafka 2.0.x -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
And now my test works well.
You can see the usage instructions of this library here.
I tried to increase Kafka version to 2.1.1 and I have an exception:
java.lang.NoClassDefFoundError: scala/Function1
So, I think the main problem is used Kafka version.