jdoe1560
jdoe1560

Reputation: 1

Scala play dependency issue

I am trying to update my Scala play application to the latest build and sbt versions, and I am getting the following error:

[error]     * org.scala-lang.modules:scala-xml_2.12:2.1.0 (early-semver) is selected over {1.2.0, 1.1.1}
[error]         +- org.scala-lang:scala-compiler:2.12.18              (depends on 2.1.0)
[error]         +- com.typesafe.sbt:sbt-native-packager:1.5.2 (scalaVersion=2.12, sbtVersion=1.0) (depends on 1.1.1)
[error]         +- com.typesafe.play:twirl-api_2.12:1.5.1             (depends on 1.2.0)

These are the main components of my build.sbt

lazy val root = (project in file(".")).enablePlugins(PlayScala)

ThisBuild / scalaVersion := "2.13.11"

libraryDependencies ++= Seq(
  caffeine,
  guice,
  "com.datastax.oss" % "java-driver-core" % "4.15.0",
  "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.2",
  "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
  "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
  "com.google.api-ads" % "ads-lib" % "5.0.0",
  "com.google.api-ads" % "dfp-axis" % "5.0.0",
  "org.typelevel" %% "cats-core" % "2.9.0",
  "com.github.tototoshi" %% "scala-csv" % "1.3.10",
  "com.github.pathikrit" %% "better-files" % "3.9.2",
  "com.google.cloud" % "google-cloud-storage" % "2.23.0",
  "com.google.apis" % "google-api-services-sheets" % "v4-rev20220927-2.0.0",
  "com.github.junrar" % "junrar" % "7.5.4",
  "com.google.oauth-client" % "google-oauth-client-jetty" % "1.34.1",
  "com.google.api-client" % "google-api-client" % "2.2.0",
  "com.sendgrid" % "sendgrid-java" % "4.9.3",
  "com.google.firebase" % "firebase-admin" % "9.2.0",
  "org.elasticsearch.client" % "elasticsearch-rest-client" % "8.8.2"
)

javaOptions in Universal ++= Seq(
  "-Dpidfile.path=/dev/null"
  // reference a logback config file that has no file appenders
)

excludeDependencies ++= Seq(
  ExclusionRule(organization = "commons-logging")
)

sbt.version=1.9.2

plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")

So, it was working okay with sbt.version=1.3.8, however I was running into the below issue when I copied some code from another repository which was using a different sbt version(1.5.2) and play plugin version(2.8.8):

[error] java.lang.ClassCastException: org.slf4j.helpers.NOPLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext

I am running this on my MacOS MX processor, java 1.8.

Tried doing some dependency overrides like below but same issue:

dependencyOverrides += "org.scala-lang.modules" %% "scala-parser-combinators" % "2.0.0"

Tried adding some log dependencies for the log issue:

libraryDependencies ++= Seq(
  "ch.qos.logback" % "logback-classic" % "1.2.3",
  "org.slf4j" % "slf4j-api" % "1.7.25"
)

But none worked.

sbt dependencyTree is also not running and failing with the conflict error

Bumping down play plugin to 2.8.8 along with sbt.version=1.3.8 works without any additional overrides though.

Any help here is appreicated, thanks!

Upvotes: 0

Views: 586

Answers (1)

Mateusz Kubuszok
Mateusz Kubuszok

Reputation: 27525

It's this issue with this workaround suggested:

// project/plugins.sbt
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always

Basically:

  • Scala XML broke backward compatibility, or at least felt that bumping major version was justified
  • it happened in a way that won't affect most of the users - including sbt
  • newer sbt prevent accidental compatibility issues by checking whether libraries use semantic versioning and what different versions are implied by dependencies and transitive dependencies, before resolving evictions
  • sbt in newer versions updated scala-xml dependency but many sbt plugins did not
  • as a result this check fails for scala-xml while compiling sbt project (the code of build.sbt and content of project/, not your code compiled by the sbt) with certain sbt plugins, but it can be silenced manually

Upvotes: 4

Related Questions