fix(common-env): 修复多插件不同协程版本导致 NoClassDefFoundError#692
Closed
zhibeigg wants to merge 1 commit into
Closed
Conversation
AetherResolver.inject() 的去重 id 仅包含依赖的 group/name, 不包含 relocate 规则信息。当多个 TabooLib 插件使用不同版本的 Kotlin Coroutines 时,先加载的插件注册了依赖 id,后加载的插件 因去重被跳过,但其模块代码已被 relocate 成引用不同版本的包名, 导致 NoClassDefFoundError。 在去重 id 中加入 relocation 规则的 hashCode,使不同 relocate 规则的同一依赖可以分别加载。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
当服务器上多个 TabooLib 插件使用不同版本的 Kotlin Coroutines 时(例如插件 A 使用 1.10.1,插件 B 使用 1.9.0),后加载的插件会抛出
NoClassDefFoundError:单独加载任一插件均正常,仅在多插件共存且协程版本不同时触发。
根因分析
AetherResolver.inject()的去重逻辑中,id 仅包含依赖的group/name和IS_ISOLATED_MODE,不包含 relocate 规则信息:这导致:
kotlinx-coroutines-core-jvm:1.10.1,relocate 为kotlin2120x.coroutines1101.*,注入成功kotlinx-coroutines-core-jvm:1.9.0,由于group/name相同被去重跳过kotlin2120x.coroutines190.*kotlin2120x.coroutines1101.*被加载 →NoClassDefFoundError修复方案
在去重 id 中加入
relocation规则的hashCode,使不同 relocate 规则的同一依赖可以分别加载,而相同 relocate 规则的同一依赖仍然会被正确去重:影响范围
AetherResolver.java一个文件