如何解决Kafka的JUnit依赖问题? [英] How to fix Kafka for JUnit dependencies problem?
问题描述
我想使用 Kafka for JUnit ,所以我添加了此依赖项:>
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
java.lang.NoClassDefFound scala/math/Ordering
如果我添加scala-library
依赖项(版本2.1.12
),则会得到:
If I add scala-library
dependency (version 2.1.12
), I get:
java.lang.NoClassDefFound com.typesafe.scalalogging.Logger $
java.lang.NoClassDefFound com.typesafe.scalalogging.Logger$
此外,我还有几个2.9.0
版本的Apache Beam
依赖项.
Also, I have several Apache Beam
dependencies with 2.9.0
version.
我可以检查些什么来解决此问题?
What can I check to solve this issue?
UPD :
如果我添加此依赖项:
<dependency>
<groupId>com.github.charithe</groupId>
<artifactId>kafka-junit</artifactId>
<version>${kafkaJunit.version}</version>
</dependency>
我得到:
java.lang.NoClassDefFoundError:scala/MatchError
java.lang.NoClassDefFoundError: scala/MatchError
如果我添加scala-library
(版本2.1.12
),则会得到:
If I add scala-library
(version 2.1.12
), I get:
java.lang.NoSuchMethodError:scala.Predef $ .refArrayOps([Ljava/lang/Object;)[Ljava/lang/Object;
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 $
java.lang.NoClassDefFound com.typesafe.scalalogging.Logger$
推荐答案
UPD
我使用@atonLitvinenko建议的 Kafka for JUnit 遇到了异常.我对此的问题在这里.
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>
此外,我将2.0.1
版本用于kafka-junit和kafka_2.11:
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
我决定通过 Salesforce 使用另一个Kafka-JUnit库.我添加了这组依赖项:
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.
我试图将Kafka版本提高到2.1.1,但有一个例外:
I tried to increase Kafka version to 2.1.1 and I have an exception:
java.lang.NoClassDefFoundError:scala/Function1
java.lang.NoClassDefFoundError: scala/Function1
所以,我认为主要问题是使用Kafka版本.
So, I think the main problem is used Kafka version.
这篇关于如何解决Kafka的JUnit依赖问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!