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

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'

Related

java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce at kafka.utils.TestUtils.tempDir(TestUtils.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?

Problem building scala 2.13.1 with Gradle 6.2 (worked with 5.6.2)

I want to use Gradle 6.2 because of the recently fixed scaladoc issue.
Here is a build scan of my Gradle build using version 5.6.2 and Scala 2.13.1 - which works fine.
Without changing the Gradle build file at all, other than changing the version to 6.2, I now get this error:
> Could not resolve all dependencies for configuration ':zinc'.
> Conflict(s) found for the following module(s):
- org.scala-lang:scala-library between versions 2.12.8, 2.12.2, 2.12.1 and 2.12.0
- com.google.protobuf:protobuf-java between versions 3.7.0 and 3.3.1
- org.scala-lang.modules:scala-xml_2.12 between versions 1.0.6 and 1.0.5
I studied the suggested dependency graph but don't know how I am supposed to resolve the conflicts. I don't know why it is trying to use scala 2.12 at all.
Here is the corresponding build scan for this failing build.
I see that dependency configurations like "compile" are now deprecated. I tried changing to the newer preferred configurations, but I'm not certain that I mapped them all correctly.
I tried this:
dependencies {
implementation "java3d:vecmath:$vecmathVersion"
testImplementation 'junit:junit:4.12'
compileOnly("org.scala-lang:scala-library") {
version {
require "2.13.1"
}
}
testImplementation 'org.scalatest:scalatest_2.13:3.1.1'
testRuntimeOnly 'org.pegdown:pegdown:1.6.0'
}
but get the same error as above.
Please see this post for a bit more detail about how gradle works with Scala dependencies.
I suggest simplifying your dependencies section first, and using a specific version of scala, to get it working. I don't see why you you only want the scala-library at compile time and not runtime? The Gradle Scala plugin requires it to be a generally compile-time dependency: https://docs.gradle.org/current/userguide/scala_plugin.html.
The same documentation says that Gradle uses 2.12 to compile 2.13 sources... so I suspect that the 2.12 dependency is creeping in because you did not explicitly declare your scala-library version.
Without knowing the value of $vecmathVersion, I suggest the following:
dependencies {
implementation group: 'java3d', name: 'vecmath', version: '1.3.1'
implementation group: 'org.scala-lang', name: 'scala-library', version: '2.13.1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.scalatest', name: 'scalatest_2.13', version: '3.1.1'
testImplementation 'org.pegdown:pegdown:1.6.0'
}

Scala gradle console app with java libararies

I have Scala console app that uses a java library. I am new to both Gradle and Scala. I am not using any IDE, just VS Code and Gradle.
I can build the app using Gradle, but when trying to run I get an exception, class not found.
$ gradle run
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class
at scopt.Head$.<init>(options.scala:148)
at scopt.Head$.<clinit>(options.scala)
at scopt.OptionParser.head(options.scala:251)
at console.App$$anon$1.<init>(App.scala:20)
at console.App$.main(App.scala:19)
at console.App.main(App.scala)
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 6 more
I am guessing that jar files are not getting copied into the build/distribution or build/libs folder.
The build file looks like:
plugins {
// Apply the scala plugin to add support for Scala
id 'scala'
id 'application'
id 'distribution'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
implementation 'org.scala-lang:scala-library:2.12.7'
implementation 'org.mongodb.scala:mongo-scala-bson_2.12:2.5.0'
implementation 'org.apache.poi:poi:4.0.1'
implementation 'org.apache.logging.log4j:log4j-core:2.11.1'
implementation 'org.apache.logging.log4j:log4j-api:2.11.1'
implementation 'org.slf4j:slf4j-nop:1.7.25'
implementation 'org.apache.poi:poi-ooxml:4.0.1'
implementation group: 'com.github.scopt', name: 'scopt_2.11', version: '3.7.1'
implementation group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api-scala_2.12', version: '11.0'
implementation 'com.github.pcj:google-options:1.0.0'
// Use Scalatest for testing our library
testImplementation 'junit:junit:4.12'
testImplementation 'org.scalatest:scalatest_2.12:3.0.5'
// Need scala-xml at test runtime
testRuntimeOnly 'org.scala-lang.modules:scala-xml_2.12:1.1.1'
}
group = 'matches'
version = '1.0'
description = 'matches'
sourceCompatibility = '11'
mainClassName = 'console.App'
application {
mainClassName = "console.App"
}
I am not sure what I need to add to the build.
You are mixing libraries os scala 2.11 and scala 2.12. Change scopt to
implementation group: 'com.github.scopt', name: 'scopt_2.12', version: '3.7.1'

IntelliJ "Cannot infer Scala class path..." but Gradle testCompile is correct?

I've got a Spring Boot project building through Gradle that recently saw the addition of some Gatling tests. The Gatlings stuff, which needs Scala support, is all down in src/test/scala. The build.gradle file got a new testCompile dependency to support it and, from a gradle perspective, all is well...
build.gradle
apply plugin: 'scala'
...
dependencies {
...
testCompile "org.scala-lang:scala-library:2.11.1"
testCompile "io.gatling.highcharts:gatling-charts-highcharts:2.2.5"
...
}
The gradle docs suggest that testCompile is all we need here: https://docs.gradle.org/current/userguide/scala_plugin.html
IntelliJ is unhappy with this configuration insisting
Warning:<i><b>root project 'tenderfoot': Unable to build Scala project configuration</b>
Details: org.gradle.api.GradleException: Cannot infer Scala class path because no Scala library Jar was found. Does root project 'tenderfoot' declare dependency to scala-library? Searched classpath: configuration ':compileClasspath'.</i>
If I lift the dependency up from testCompile to compile, the intellij warning goes away, but now my spring boot uber jar thing is unnecessarily bloated.
What's the way out? How do I get IntelliJ to stop Warning on this?
Is this actually an IntelliJ bug?
I ran into this problem also (having to set the dependency manually from IntelliJ).
I "fixed" it by setting the dependency as compileOnly as opposed to compile, this scope does not include the JAR in the final distribution.
The code I use is (please note that my dependency includes Scala as a transitive dependency):
compileOnly("io.gatling.highcharts:gatling-charts-highcharts:$gatlingVersion")

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.