java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce at kafka.utils.TestUtils.tempDir(TestUtils.scala) - scala

While using #EmbeddedKafka(topics = { "checkins" })
I am getting an error
Caused by: java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce
at kafka.utils.TestUtils.tempDir(TestUtils.scala)
at org.springframework.kafka.test.EmbeddedKafkaBroker$EmbeddedZookeeper.<init>(EmbeddedKafkaBroker.java:738)
at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
I am using spring boot 2.3.3.RELEASE
My gradle looks like
compile("io.confluent:kafka-json-serializer:$confluentJsonVersion")
compile ("org.apache.kafka:kafka-clients: $kafkaVersion")
implementation ("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.kafka:spring-kafak:$springKafkaVersion")
implementation "org.apache.kafka:kafka-clients:$kafkaVersion"
testImplementation("org.springframework.kafka:spring-kafka-test:$springKafkaVersion")
testImplementation("org.apache.kafka:kafka_2.13:$kafkaVersion")
testImplementation("org.apache.kafka:kafka_2.13:$kafkaVersion:test")
testImplementation ("org.apache.kafka:kafka-clients:$kafkaVersion:test")

That interface only exists in the kafka_2.12 jars.
It appears you somehow have a 2.12 ...-test jar and a 2.13 kafka jar (which is not what your gradle says).
What does gradle dependencies say?

Related

Upgrade to spring-geode-starter 1.4.2 produces condition, introspection and ClassNotFoundExceptions

On return to a Geode reactive streams project after some time I would like to upgrade to latest spring-geode-starter. Perhaps related to Spring Boot Geode Unsatisfied dependency expressed through method 'sessionRegion' also on ClientCacheConfiguration what I think is a simple build.gradle dependencies gives exception:
2021-02-03T07:36:55,171 ERROR [main] org.springframework.boot.SpringApplication 856 reportFailure: Application run failed
java.lang.IllegalStateException: Error processing condition on org.springframework.geode.boot.autoconfigure.CachingProviderAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:489)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:478)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:478)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:140)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:348)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:252)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:285)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:99)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
at app.FixApi.main(FixApi.java:23)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#2f333739]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:754)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1737)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:753)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:692)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:663)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:238)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:231)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:221)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:169)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:119)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
... 20 more
Caused by: java.lang.NoClassDefFoundError: org/apache/geode/cache/client/SocketFactory
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 36 more
Caused by: java.lang.ClassNotFoundException: org.apache.geode.cache.client.SocketFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 40 more
My build.gradle dependencies are:
dependencies {
group = 'api'
description = 'streaming api'
// This dependency is exported to consumers, that is to say found on their compile classpath.
// api 'org.apache.commons:commons-math3:3.6.1'
// Geode client dependency
implementation 'org.springframework.geode:spring-geode-starter:1.4.2'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.4.2'
implementation 'com.lmax:disruptor:3.4.2'
implementation 'org.springframework.boot:spring-boot-starter-webflux:2.4.2'
implementation 'org.springframework.boot:spring-boot-starter-rsocket:2.4.2'
// tag::actuator[]
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.4.2'
// end::actuator[]
// HTML manager
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf:2.4.2'
implementation 'com.google.guava:guava:30.1-jre'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.json:json:20201115'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'org.projectlombok:lombok:1.18.16'
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.1'
// Geode tests
testImplementation 'org.springframework.data:spring-data-geode-test:0.0.22'
// Other test dependencies
testImplementation 'io.projectreactor:reactor-test:3.4.2'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.data:spring-data-geode-test:0.0.22'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.4.2'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
I am not exactly sure how (reviewing your dependencies in the Gradle build shown above), but the NoClassDefFoundError/ClassNotFoundException on the Apache Geode API class org.apache.geode.cache.client.SocketFactory is caused by an incompatible version of Apache Geode (i.e. a version prior to 1.13).
The SocketFactory class was in fact introduced in Apache Geode 1.13 (see here, then try here).
Indeed SBDG 1.4.2 pulls in SDG 2.4.3, which is based on Apache Geode 1.13.1. This is also apparent from the SBDG Version Compatibility Matrix.
You might try running:
$ gradlew dependencies | less
And searching for all the org.apache.geode:geode-core dependencies (simply search for "geode-core") and see which versions of Apache Geode are being used, overridden, etc.
But, anytime you see a NoClassDefFoundError/ClassNotFoundException or NoSuchMethodError, errors of that nature, you can bet that 9 out of 10 times you have a version problem.
This was solved by checking out the Version-Compatibility-and-Support-Matrix and selecting
implementation 'org.springframework.geode:spring-geode-starter:1.2.8.RELEASE'

Caused by: java.lang.ClassNotFoundException: org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer

i have a kafkaflink job which works in intellij, on packaging with sbt i get the below message
Caused by: java.lang.ClassNotFoundException:
org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
Thanks for having a look at it
You most certainly have Kafka as provided dependency or you are not creating the fat-jar.
You need to use a plugin depending on the build tool You are using for sbt it can be sbt assembly, for maven it can be maven-shade-plugin. And then You need to have flink-kafka-connector in compile scope.

Test runs on command line, fails in Scala-IDE

When right-click running a test class, Eclipse failed with
Caused by: java.lang.NoClassDefFoundError: scala/Product$class
at org.scalatest.time.Days$.<init>(Units.scala:291)
at org.scalatest.time.Days$.<clinit>(Units.scala)
at org.scalatest.time.Span$.<init>(Span.scala:585)
at org.scalatest.time.Span$.<clinit>(Span.scala)
at org.scalatest.tools.Runner$.<init>(Runner.scala:779)
at org.scalatest.tools.Runner$.<clinit>(Runner.scala)
at org.scalatest.tools.Runner.main(Runner.scala)
... 6 more
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Yet it ran in the command line with sbt test. The libraries have been updated as described in java.lang.NoClassDefFoundError: scala/Product$class.
This happened with the latest Scala IDE (4.7.0-vfinal-2017-09-29T14:34:02Z-Typesafe) with the patmat project from Coursera's scala course.
What is the cause and how can it be fixed?
Requested info
The Java Build Path is
You have a combination of _2.11 libraries and 2.12.3 Scala library, this won't work. It looks like the _2.11 dependendencies come from SBT (judging from the paths).
You need to either change Scala IDE's Scala version (setting correct scala version on scala ide explains how) or set scalaVersion := "2.12.3" in the SBT project and rerun sbt eclipse.
Please use the Scala library version 2.11 as the other Scala based dependencies like scala-xml and scalatest are based on Scala library version 2.11

Specs2 Tests Fail to Run Natively in IntelliJ

Running Specs2 in IntelliJ fails. Running the same tests manually via an SBT task works just fine without any problems.
Message: "Test framework quit unexpectedly"
IntelliJ: v.15.0.5 or 2016.2 EAP (build #IC-162.426.1)
Platform: Scala 2.11.7, SBT 0.13.8, Specs2 2.4.17, Play! 2.3.10
This is a common error response, but it looks like the root cause is different for a lot of other people. I have troubleshoot this issue before and corrected it by adding the following to build.sbt:
fork in Test := false
parallelExecution in Test := false
Now the tests are failing again. I have looked through the revision history of our build.sbt file but I do not notice anything significant that would instigate such a regression and I have no clues.
Upon step-debugging the crash I have found the following root cause:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.specs2.reflect.Classes$class.createInstanceFor(Classes.scala:154)
at org.specs2.reflect.Classes$.createInstanceFor(Classes.scala:207)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:145)
at scala.Option.map(Option.scala:146)
at org.specs2.reflect.Classes$class.createInstanceOfEither(Classes.scala:145)
at org.specs2.reflect.Classes$.createInstanceOfEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.org$specs2$reflect$Classes$$createInstanceForConstructor(Classes.scala:118)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at org.specs2.reflect.Classes$$anonfun$4.apply(Classes.scala:98)
at scala.collection.immutable.List.map(List.scala:273)
at org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:98)
at org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:207)
at org.specs2.reflect.Classes$class.tryToCreateObject(Classes.scala:70)
at org.specs2.reflect.Classes$.tryToCreateObject(Classes.scala:207)
at org.specs2.specification.SpecificationStructure$.createSpecificationFromClassOrObject(BaseSpecification.scala:126)
at org.specs2.specification.SpecificationStructure$.createSpecificationOption(BaseSpecification.scala:107)
at org.specs2.specification.SpecificationStructure$.createSpecification(BaseSpecification.scala:95)
at org.specs2.runner.ClassRunner.createSpecification(ClassRunner.scala:60)
at org.specs2.runner.ClassRunner.start(ClassRunner.scala:31)
at org.specs2.runner.NotifierRunner.start(NotifierRunner.scala:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSpecs2_old(JavaSpecs2Runner.java:133)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSingleTest(JavaSpecs2Runner.java:204)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:85)
Caused by: java.lang.IncompatibleClassChangeError: Found class scalaz.Tree, but interface was expected
at org.specs2.mutable.SideEffectingCreationPaths$class.$init$(FragmentsBuilder.scala:245)
at org.specs2.mutable.Specification.<init>(Specification.scala:12)
at controllers.VerificationApiSpec.<init>(VerificationApiSpec.scala:26)
... 32 more
scalaz.Tree is a transitive dependency of many other dependencies in my project that request versions including 7.1.1, 7.1.2, 7.1.3, 7.0.6 of scalaz. It's interesting to note that in 7.0.x scalaz.Tree is a trait (interface in Java vernacular) but an abstract class in 7.1.x, so this may constitute the root cause.
Is it possible to resolve this issue given the transitive dependency conflicts with scalaz 7.1.x and 7.0.x which are evidentially incompatible?
Specs2 2.4.17 uses Scalaz 7.1.0. Some other dependency in your build is probably dragging a Scalaz 7.2.x dependency. I suggest that you update your specs2 version to 3.8.4 which will bring a more recent version of Scalaz in scope.

Maven: Failed to load class for data source: com.databricks.spark.csv

I have a Maven project and I can't make it run:
Exception in thread "main" java.lang.ClassNotFoundException: Failed to load class for data source: com.databricks.spark.csv.
How to fix this in Maven?
PS: I know about this question, but I cannot use any additional options to spark-submit, except --class and --master.
Try maven-shade-plugin in you pom it will create one shade jar with your all dependencies or classes. For more detail go through this link