I just setup a new Spring Boot application with GraphQL Java Tools. The precise versions in my Maven pom.xml file are:
com.graphql-java-kickstart:graphql-spring-boot-starter:12.0.0
com.graphql-java-kickstart:graphiql-spring-boot-starter:11.1.0
com.graphql-java-kickstart:graphql-java-tools:12.0.0
Although my application compiles, when I start my Spring Boot application, it fails with the following cryptic error:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
graphql.kickstart.tools.resolver.FieldResolverScanner.findResolverMethod(FieldResolverScanner.kt:92)
The following method did not exist:
'java.lang.String kotlin.text.CharsKt.titlecase(char)'
The method's class, kotlin.text.CharsKt, is available from the following locations:
jar:file:/C:/Users/c-martind/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.3.61/kotlin-stdlib-1.3.61.jar!/kotlin/text/CharsKt.class
It was loaded from the following location:
file:/C:/Users/c-martind/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.3.61/kotlin-stdlib-1.3.61.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of kotlin.text.CharsKt
I am using Java instead of Kotlin so I don't know why it's having an issue with Kotlin.
CodePudding user response:
As per GraphQL Java Tools's README you need to set the Kotlin version in your <properties>
section in your Maven pom.xml
file:
<properties>
<kotlin.version>1.5.0</kotlin.version>
</properties>
If you're using graphl-java-tools
with Spring Boot you may run into Kotlin version mismatches because both depend on Kotlin. Specifically, Spring Boot Starter may override the version with a version lower than required by GraphQL Java Tools. Setting the above property will bump the Kotlin version to the appropriate version. If you don't override this version you will run into an error like NoClassDefFoundError
or the one you encountered during application startup.