scalajacksonsbt

Jackson Databind Version Error on a Scala Project When running tests


I'm hitting a strange error all of a sudden in my project which is a Play Framework application. Until yesterday, my sbt tests were running fine and now it fails with a run abort. The only difference being that I added a new dependency:

"io.fabric8" % "kubernetes-client" % "6.9.0",

When I ran

sbt clean test

I got the following error message:

An exception or error caused a run to abort: Scala module 2.11.4 requires Jackson Databind version >= 2.11.0 and < 2.12.0 
com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.11.4 requires Jackson Databind version >= 2.11.0 and < 2.12.0
    at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:61)
    at com.fasterxml.jackson.module.scala.JacksonModule.setupModule$(JacksonModule.scala:46)
    at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:17)
    at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:879)
    at akka.serialization.jackson.JacksonObjectMapperProvider$.$anonfun$configureObjectMapperModules$4(JacksonObjectMapperProvider.scala:242)
    at akka.serialization.jackson.JacksonObjectMapperProvider$.$anonfun$configureObjectMapperModules$4$adapted(JacksonObjectMapperProvider.scala:241)
    at scala.collection.immutable.List.foreach(List.scala:333)
    at akka.serialization.jackson.JacksonObjectMapperProvider$.configureObjectMapperModules(JacksonObjectMapperProvider.scala:241)
    at akka.serialization.jackson.JacksonObjectMapperProvider$.createObjectMapper(JacksonObjectMapperProvider.scala:265)
    at akka.serialization.jackson.JacksonObjectMapperProvider.create(JacksonObjectMapperProvider.scala:359)
    at akka.serialization.jackson.JacksonObjectMapperProvider.$anonfun$getOrCreate$1(JacksonObjectMapperProvider.scala:317)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at akka.serialization.jackson.JacksonObjectMapperProvider.getOrCreate(JacksonObjectMapperProvider.scala:317)
    at akka.serialization.jackson.JacksonJsonSerializer.<init>(JacksonSerializer.scala:141)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at akka.actor.ReflectiveDynamicAccess.$anonfun$createInstanceFor$1(ReflectiveDynamicAccess.scala:40)
    at scala.util.Try$.apply(Try.scala:210)

I seriously do not know from where it is pulling the scala module 2.11 as my project is depending on scala 2.13. I ran the sbt dependencyTree and here I can see that the jackson databind version is always evicted like this:

+-com.fasterxml.jackson.core:jackson-databind:2.11.4 (evicted by: 2.15.2)

I have one other test dependency like this:

"io.fabric8" % "kubernetes-server-mock" % "6.9.0" % Test

I realized that after removing this, the problem vanished. So I trust that this test dependency is actually causing this error, but I need to have this library for testing purposes. How can I fix this error?


Solution

  • All Jackson libraries pulled by your project transitively (or directly) must have the same minor version 2.x.

    Here you are pulling Jackson Scala module 2.11.x but apparently also pulling Jackson Databind 2.15.x.

    This is because you have at least two dependencies which themselves pull Jackson in different versions.

    To solve the situation, you should define dependencyOverrides in your build.sbt to fix a common minor version for all Jackson libraries.