mamoe / mirai

高效率 QQ 机器人支持库
https://mirai.mamoe.net
GNU Affero General Public License v3.0
14.5k stars 2.54k forks source link

Caused by: java.util.ServiceConfigurationError: io.ktor.client.HttpClientEngineContainer: Provider io.ktor.client.engine.okhttp.OkHttpEngineContainer not found #2667

Open ForteScarlet opened 1 year ago

ForteScarlet commented 1 year ago

问题描述

在使用mirai的同时使用Ktor的时候,使用 HttpClient() 会出现标题所述异常:

Caused by: java.util.ServiceConfigurationError: io.ktor.client.HttpClientEngineContainer: Provider io.ktor.client.engine.okhttp.OkHttpEngineContainer not found

似乎是在打 shadow 包的时候将 ktor-client-okhttpMETA-INF/services 里的文件也打进去了,但实际上最终并没有此依赖的引用。

目前可以通过手动添加 ktor-client-okhttp 依赖来解决,但是我认为这仍然是个问题。

复现

// build.gradle.kts
// mirai依赖...
implementation("io.ktor:ktor-client-cio:2.3.0")
HttpClient() // error

mirai-core 版本

2.14.0

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

Caused by: java.util.ServiceConfigurationError: io.ktor.client.HttpClientEngineContainer: Provider io.ktor.client.engine.okhttp.OkHttpEngineContainer not found
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593) ~[na:na]
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219) ~[na:na]
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228) ~[na:na]
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273) ~[na:na]
    at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309) ~[na:na]
    at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393) ~[na:na]
    at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1295) ~[kotlin-stdlib-1.7.22.jar:1.7.22-release-288(1.7.22)]
    at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1328) ~[kotlin-stdlib-1.7.22.jar:1.7.22-release-288(1.7.22)]
    at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1319) ~[kotlin-stdlib-1.7.22.jar:1.7.22-release-288(1.7.22)]
    at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:39) ~[ktor-client-core-jvm-2.3.0.jar:2.3.0]
    at love.forte.simbot.qguild.internal.BotImpl.<init>(BotImpl.kt:97) ~[simbot-component-qq-guild-stdlib-jvm-3.0.0.0-alpha.7.jar:na]
    at love.forte.simbot.qguild.BotFactory.create(BotConfiguration.kt:46) ~[simbot-component-qq-guild-stdlib-jvm-3.0.0.0-alpha.7.jar:na]
    at love.forte.simbot.component.qguild.internal.QQGuildBotManagerImpl.register(QQGuildBotManagerImpl.kt:137) ~[simbot-component-qq-guild-core-3.0.0.0-alpha.7.jar:na]
    at love.forte.simbot.component.qguild.BaseQQGuildBotManager.register(BaseQQGuildBotManager.kt:75) ~[simbot-component-qq-guild-core-common-3.0.0.0-alpha.7.jar:na]
    at love.forte.simbot.component.qguild.BaseQQGuildBotManager.register(BaseQQGuildBotManager.kt:46) ~[simbot-component-qq-guild-core-common-3.0.0.0-alpha.7.jar:na]
    at love.forte.simboot.spring.autoconfigure.SimbotSpringBootBotAutoRegisterBuildConfigure$SimbotSpringBootBotAutoRegisterPostProcessor.register(SimbotSpringBootBotAutoRegisterBuildConfigure.kt:164) ~[simboot-core-spring-boot-starter-3.0.0.jar:na]
    at love.forte.simboot.spring.autoconfigure.SimbotSpringBootBotAutoRegisterBuildConfigure$SimbotSpringBootBotAutoRegisterPostProcessor.config(SimbotSpringBootBotAutoRegisterBuildConfigure.kt:115) ~[simboot-core-spring-boot-starter-3.0.0.jar:na]
    at love.forte.simboot.spring.autoconfigure.SimbotSpringBootBotAutoRegisterBuildConfigure$SimbotSpringBootBotAutoRegisterPostProcessor.access$config(SimbotSpringBootBotAutoRegisterBuildConfigure.kt:46) ~[simboot-core-spring-boot-starter-3.0.0.jar:na]
    at love.forte.simboot.spring.autoconfigure.SimbotSpringBootBotAutoRegisterBuildConfigure$SimbotSpringBootBotAutoRegisterPostProcessor$config$1.invokeSuspend(SimbotSpringBootBotAutoRegisterBuildConfigure.kt) ~[simboot-core-spring-boot-starter-3.0.0.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.7.22.jar:1.7.22-release-288(1.7.22)]
    at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:178) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.ResumeOnCompletion.invoke(JobSupport.kt:1398) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.notifyCompletion(JobSupport.kt:1520) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:323) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:240) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.continueCompleting(JobSupport.kt:935) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.access$continueCompleting(JobSupport.kt:27) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport$ChildCompletion.invoke(JobSupport.kt:1155) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.notifyCompletion(JobSupport.kt:1520) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:323) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:240) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:906) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:863) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:828) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) ~[kotlin-stdlib-1.7.22.jar:1.7.22-release-288(1.7.22)]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) ~[kotlinx-coroutines-core-jvm-1.6.4.jar:na]

网络日志

No response

补充信息

No response

Karlatemp commented 1 year ago

https://imperceptiblethoughts.com/shadow/configuration/merging/#merging-service-descriptor-files

ForteScarlet commented 1 year ago

是否考虑在发布 mirai-core 的时候排除掉Jar内的 META-INF/services/io.ktor.client.HttpClientEngineContainer 文件呢?否则经常会导致 ServiceLoader 加载出现异常,如果忘了加 ktor-client-okhttp 的话

Karlatemp commented 1 year ago

@Him188

Him188 commented 1 year ago

确实需要删掉

Him188 commented 1 year ago

目前你使用 HttpClient(CIO) 可作为临时解决方案