slf4j 版本不匹配以及与 kotlin-main-kts 的多重绑定

问题描述 投票:0回答:1

我正在使用 Maven 开发 Quarkus 项目,该项目具有多个模块并包含 kotlin-main-kts 库。 以下是有关我的错误的信息:

  • 我有多个 slf4j 绑定错误/警告
  • 我也有版本不匹配的情况,导致我无法启动该项目
  • 在本地,我可以运行该项目,但当我打包并尝试使用 docker 运行时却不能运行
  • 消息是
    The requested version 2.0.6 by your slf4j binding is not compatible with [1.6, 1.7]
  • 最后,它崩溃了并显示另一条消息:
    Caused by: java.lang.NoSuchMethodError: 'org.slf4j.helpers.FormattingTuple org.slf4j.helpers.MessageFormatter.format(java.lang.String, java.lang.Object)'
  • 根据下面的堆栈跟踪,有两个绑定:
    • org.jboss.slf4j.slf4j-jboss-logmanager-2.0.0.Final.jar
    • org.jetbrains.kotlin.kotlin-main-kts-1.9.10.jar

请注意,

slf4j-jboss-logmanager
是Quarkus的对等依赖项,在主pom.xml中导入,
kotlin-main-kts
是直接依赖项,在项目的子模块依赖项中导入。

奇怪的是,如果我显示依赖关系树 (

mvn dependency:tree -Dincludes=*slf4j*
),slf4j 将不会显示为 kotlin-main-kts 依赖关系,而它是用于 jboss-logmanager:

[INFO] com.my.package:produit:jar:1.0.12-SNAPSHOT
[INFO] +- io.quarkus:quarkus-rest-client:jar:3.4.3:compile
[INFO] |  \- io.quarkus:quarkus-core:jar:3.4.3:compile
[INFO] |     \- org.jboss.slf4j:slf4j-jboss-logmanager:jar:2.0.0.Final:compile
[INFO] \- io.mockk:mockk-jvm:jar:1.13.4:test
[INFO]    \- org.slf4j:slf4j-api:jar:2.0.6:compile

所以我尝试了很多东西,比如依赖管理、排除,但它似乎不起作用,但这是我第一次这样做,所以也许我做错了什么。 我认为这可能与 kotlin-main-kts 包含 jar 的方式有关

堆栈跟踪

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/jboss/lib/main/org.jboss.slf4j.slf4j-jboss-logmanager-2.0.0.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/jboss/lib/main/org.jetbrains.kotlin.kotlin-main-kts-1.9.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Slf4jLoggerFactory]
SLF4J: The requested version 2.0.6 by your slf4j binding is not compatible with [1.6, 1.7]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
The DelayedHandler was closed before any children handlers were configured. Messages will be written to stderr.
2023-11-03 09:42:26,816 DEBUG [org.jboss.logging] (main) Logging Provider: org.jboss.logging.JBossLogManagerProvider

2023-11-03 09:42:28,808 DEBUG [io.netty.util.internal.logging.InternalLoggerFactory] (main) Using SLF4J as the default logging framework

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:61)
    at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:32)
Caused by: java.lang.ExceptionInInitializerError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:70)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
    at io.quarkus.runner.GeneratedMain.main(Unknown Source)
    ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
    at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
    ... 15 more
Caused by: java.lang.NoSuchMethodError: 'org.slf4j.helpers.FormattingTuple org.slf4j.helpers.MessageFormatter.format(java.lang.String, java.lang.Object)'
    at io.netty.util.internal.logging.LocationAwareSlf4JLogger.debug(LocationAwareSlf4JLogger.java:108)
    at io.netty.util.internal.InternalThreadLocalMap.<clinit>(InternalThreadLocalMap.java:100)
    at io.netty.util.concurrent.FastThreadLocal.<init>(FastThreadLocal.java:128)
    at io.quarkus.vertx.runtime.VertxCurrentContextFactory$VertxCurrentContext.<init>(VertxCurrentContextFactory.java:26)
    at io.quarkus.vertx.runtime.VertxCurrentContextFactory.create(VertxCurrentContextFactory.java:21)
    at io.quarkus.arc.impl.ArcContainerImpl.<init>(ArcContainerImpl.java:194)
    at io.quarkus.arc.Arc.initialize(Arc.java:39)
    at io.quarkus.arc.runtime.ArcRecorder.initContainer(ArcRecorder.java:47)
    at io.quarkus.deployment.steps.ArcProcessor$generateResources844392269.deploy_0(Unknown Source)
    at io.quarkus.deployment.steps.ArcProcessor$generateResources844392269.deploy(Unknown Source)
    ... 16 more
maven slf4j
1个回答
0
投票

我解决了这个问题。事实上,冲突发生在

netty-common
kotlin-main-kts
之间(如果我们查看堆栈跟踪,就会发现有一个
at io.netty.util.internal.logging.LocationAwareSlf4JLogger
)。

原因是 kotlin-main-kts 使用了一种奇怪的方式来添加 slf4j 依赖项,我无法解释为什么,但是 netty 依赖于这个依赖项,而不是 maven 包含在 jar 中的依赖项(并且包含在正确的版本 2.0.6 中)。

我做了什么:我删除了对 kotlin-main-kts 的依赖,而是添加了 kotlin-main-kts 的 3 个依赖(kotlin-stdlib、kotlin-scripting-compiler-embeddable、kotlin-reflect),这在我的情况。 这很hacky,但这是我发现让它发挥作用的唯一方法。

© www.soinside.com 2019 - 2024. All rights reserved.