I'm upgrading the application to scala version 2.12. The application is using a library which has been developed by another team in scala 2.11.
Here is my updated code of file build.sbt. It's using the library "sdp-commons-monitoring_2.11"
import com.typesafe.sbt.SbtNativePackager.autoImport.NativePackagerHelper._
import sbt.{Artifact, Credentials, Defaults, Level, addArtifact}
lazy val commonSettings = Seq(
scalaVersion := "2.12.15",
organization := "com.pi.isg.ingest"
)
name := "ingest-tool"
libraryDependencies = "com.pi.isg.sdp-commons" % "sdp-commons-monitoring_2.11" % "11.1.9" excludeAll(
ExclusionRule(organization = "org.json4s"),
ExclusionRule(organization = "org.scala-lang"),
ExclusionRule(organization = "io.spray"),
ExclusionRule(organization = "org.slf4j"),
ExclusionRule(organization = "ch.qos.logback"),
ExclusionRule(organization = "com.amazonaws"),
ExclusionRule(organization = "com.typesafe.akka"),
ExclusionRule(organization = "com.fieldstreams.dispatcher"),
ExclusionRule(organization = "com.pi.fieldstreams.persistence"),
ExclusionRule(organization = "com.pi.isg.sdp-commons", name = "sdp-commons-common-persistence_2.11"),
ExclusionRule(organization = "com.pi.isg.sdp-commons", name = "sdp-commons-serialization_2.11")
)
When running the application, it thrown an error "java.lang.NoClassDefFoundError: scala/Product$class sbt.ForkMain$ForkError: java.lang.NoClassDefFoundError: scala/Product$class". It seems that is compatibility version problem. Is there any way to config in build.sbt so my application run with scala version 2.12 and the lib goes with scala version 2.11?
At this time, the team who has developed the lib has no plan to upgrade their lib to new version.
Regards,
CodePudding user response:
As mentionned in a comment: Scala 2 minor versions (where "minor" is used in the general semver meaning: major.minor.patch
) are not binary compatible.
Thus, for instance, a library compiled with Scala 2.11 cannot be used in a Scala 2.12 project.
This has started to changed with Scala 3:
- libraries compiled with Scala 2.13 can be used in a Scala 3 project and vice versa, with the exception of libraries using macros
- Scala 3 minor versions are backwards binary compatible (3.1 project can use a 3.0 library but not yet the opposite, although this is progressively changing and forward compatibility might be possible in the future).
See more documentation about this: