我的 Play Framework 项目有以下依赖项:
"io.getquill" %% "quill-jdbc" % "4.3.0",
"org.postgresql" % "postgresql" % "42.3.1",
"com.h2database" % "h2" % "1.4.199",
"org.tpolecat" %% "doobie-core" % DoobieVersion,
"org.tpolecat" %% "doobie-postgres" % DoobieVersion,
"org.tpolecat" %% "doobie-h2" % DoobieVersion,
"org.tpolecat" %% "doobie-hikari" % DoobieVersion,
"com.typesafe.play" %% "play-json" % "2.9.3",
"com.typesafe.play" %% "play-json-joda" % "2.9.3",
// Threading & Streaming libraries (https://monix.io/docs/current/intro/usage.html)
"io.monix" %% "monix-execution" % "3.4.0",
//"io.monix" %% "monix-eval" % "3.4.0",
//"io.monix" %% "monix-reactive" % "3.4.1",
"io.monix" %% "monix-reactive" % "3.4.1" exclude("org.typelevel", "cats-effect_2.13"),
"org.typelevel" %% "cats-effect" % "3.5.1",
// Test libraries
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
"org.specs2" %% "specs2-core" % "4.20.0" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.1" % Test
当我尝试运行我的项目时,它失败并出现以下错误:
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/home/joesan/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
[error] java.lang.ClassCastException: class org.slf4j.helpers.NOPLoggerFactory cannot be cast to class ch.qos.logback.classic.LoggerContext (org.slf4j.helpers.NOPLoggerFactory and ch.qos.logback.classic.LoggerContext are in unnamed module of loader play.runsupport.NamedURLClassLoader @b900ff7)
[error] at play.api.libs.logback.LogbackLoggerConfigurator.configure(LogbackLoggerConfigurator.scala:91)
[error] at play.api.libs.logback.LogbackLoggerConfigurator.init(LogbackLoggerConfigurator.scala:31)
[error] at play.core.server.DevServerStart$.$anonfun$mainDev$1(DevServerStart.scala:106)
[error] at play.utils.Threads$.withContextClassLoader(Threads.scala:22)
[error] at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:76)
[error] at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:50)
[error] at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] at play.runsupport.Reloader$.startDevMode(Reloader.scala:306)
[error] at play.sbt.run.PlayRun$.devModeServer$lzycompute$1(PlayRun.scala:100)
[error] at play.sbt.run.PlayRun$.devModeServer$1(PlayRun.scala:83)
[error] at play.sbt.run.PlayRun$.$anonfun$playRunTask$3(PlayRun.scala:107)
[error] at play.sbt.run.PlayRun$.$anonfun$playRunTask$3$adapted(PlayRun.scala:67)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) java.lang.reflect.InvocationTargetException
[error] Total time: 1 s, completed Sep 6, 2023, 9:33:00 PM
我知道某个地方存在一些令人讨厌的传递依赖,但不确定如何识别并修复它。
编辑:运行 sbt evicted 给了我这个:
[warn] * org.slf4j:slf4j-api:2.0.7 is selected over {1.7.30, 1.7.36, 1.7.36, 1.7.36, 1.7.30, 2.0.0-alpha1, 1.7.25, 1.7.36, 1.7.36, 1.7.32}
[warn] +- ch.qos.logback:logback-classic:1.4.11 (depends on 2.0.7)
[warn] +- org.tpolecat:doobie-hikari_2.13:1.0.0-RC1 (depends on 1.7.32)
[warn] +- org.slf4j:jul-to-slf4j:1.7.36 (depends on 1.7.36)
[warn] +- org.slf4j:jcl-over-slf4j:1.7.36 (depends on 1.7.36)
[warn] +- org.java-websocket:Java-WebSocket:1.4.0 (depends on 1.7.25)
[warn] +- com.zaxxer:HikariCP:4.0.3 (depends on 2.0.0-alpha1)
[warn] +- com.typesafe.scala-logging:scala-logging_2.13:3.9.4 (depends on 1.7.30)
[warn] +- com.typesafe.play:play_2.13:2.8.19 (depends on 1.7.36)
[warn] +- com.typesafe.akka:akka-slf4j_2.13:2.6.20 (depends on 1.7.36)
[warn] +- com.typesafe.akka:akka-actor-typed_2.13:2.6.20 (depends on 1.7.36)
[warn] +- com.openelectrons:ocpp-j-api_2.13:0.0.1-SNAPSHOT (depends on 1.7.30)
在编写这些行时(2023 年 8 月),在 Play 应用程序 (2.8.19) 中,您可能会强制 SLF4J、logback 甚至其他日志库之间发生冲突。
简短的回答是:
为此,使用
dependencyOverrides
强制使用特定版本的SLF4J和logback(这应该至少有5个依赖项,如slf4j-api
、jul-to-slf4j
、jcl-over-slf4j
、logback-core
、logback-classic
..) .我并不认识它们,但 sbt dependencyBrowseTree
或类似的命令将有助于找到它们)。