Skip to content

移除 guice 依赖 #139

Closed
Closed

Description

@refeccd

这个 pull_request 移除guice了依赖,但是没有下文了,想知道还有计划吗?

在新版jdk里,已经warning了

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/Applications/IntelliJ%20IDEA.app/Contents/plugins/maven/lib/maven3/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release

Activity

  1. nobodyiam commented on May 16, 2026

    @nobodyiam
    Member

    感谢反馈。这里可以拆开看:

    1. 这类 warning 的根因是新版 JDK 开始对 sun.misc.Unsafe 的 memory-access 方法给出运行期告警。比如 Unsafe.staticFieldBase(Field) 已经被标记为 terminally deprecated,JDK 24/25 会默认打印 warning,后续 JDK 版本还可能进一步收紧。

    2. 你贴出来的这条 warning 里,触发方是 IntelliJ IDEA 内置 Maven 的 Guice:

      .../IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/lib/guice-5.1.0-classes.jar

      所以这条具体 warning 不是 Apollo Java 运行时触发的;即使 Apollo Java 立刻移除 Guice,也不会消除 Maven/IDEA 自己启动时加载 Guice 产生的 warning。

    3. 从 Guice 角度看,这确实是 Guice 的通用兼容问题。com.google.inject.internal.aop.HiddenClassDefiner 内部使用了 Unsafe.staticFieldBase,Guice upstream 已经有类似 issue 在跟踪,而且 Guice 7.0.0 也仍然会触发同类 warning。因此最根本的修复应该由 Guice 在后续版本中改掉这段 Unsafe 用法。

    不过,从 Apollo Java 自身维护角度看,apollo-client 目前仍然有 com.google.inject:guice 的 compile 依赖,长期来看减少这类运行时依赖、降低未来 JDK 升级风险是合理方向。但这不是一个简单升级 Guice 版本就能解决的问题,也不是修复上面 Maven warning 的直接手段。

    如果后续要推进移除 Guice,建议作为 enhancement/discussion 来做,重点是保持现有 ApolloInjector、Injector、ApolloInjectorCustomizer 扩展点、singleton 生命周期以及 apollo-client-config-data 相关行为兼容,并补齐对应测试。

  2. refeccd commented on May 16, 2026

    @refeccd
    Author

    确实这个warning不是由项目里的guice引起,而是由idea内部引起(只是记得apollo里有就以为是apollo引起的,sorry)。

  3. stale commented on Jun 26, 2026

    @stale

    This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions