You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Hibernate 6后出现kotlin.Metadata警告的解决咨询

解决Hibernate 6升级后Kotlin.Metadata相关编译警告问题

问题背景

未使用Kotlin的项目升级到Hibernate 6后,开启-Xlint:all编译参数时出现如下警告:

[INFO] Hibernate compile-time tooling 6.5.2.Final
[WARNING] Cannot find annotation method 'mv()' in type 'kotlin.Metadata': class file for kotlin.Metadata not found
[WARNING] Cannot find annotation method 'k()' in type 'kotlin.Metadata'
[WARNING] Cannot find annotation method 'xi()' in type 'kotlin.Metadata'
[WARNING] Cannot find annotation method 'd1()' in type 'kotlin.Metadata'
[WARNING] Cannot find annotation method 'd2()' in type 'kotlin.Metadata'

原因是Hibernate 6的注解处理器在处理依赖库中带有kotlin.Metadata注解的类时,本地编译环境缺少Kotlin元数据类,加上全量lint检查触发了该警告。

解决方案

方案一:添加Kotlin标准库的编译期依赖(推荐)

在Maven的pom.xml中添加以下依赖,仅用于编译阶段提供kotlin.Metadata类,不会影响运行时:

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>1.9.20</version> <!-- 选用与Hibernate兼容的稳定版即可 -->
    <scope>provided</scope>
</dependency>

添加后,编译器能找到kotlin.Metadata类,相关警告会自动消失,同时保留其他所有编译警告。

方案二:精确禁用对应lint警告

若不想引入Kotlin依赖,可尝试在compilerArgs中添加针对注解相关警告的禁用参数:

<compilerArgs>
    <arg>-Xlint:all</arg>
    <arg>-Xmaxwarns</arg>
    <arg>50000</arg>
    <arg>-Xlint:-processing</arg>
    <arg>-Xlint:-options</arg>
    <arg>-Xlint:-serial</arg>
    <arg>-Xlint:-annotation</arg> <!-- 新增此参数禁用注解相关警告 -->
    <arg>-AaddSuppressWarningsAnnotation=true</arg>
</compilerArgs>

注意:此方法可能会禁用其他注解相关的有用警告,需根据实际情况评估。

内容的提问来源于stack exchange,提问作者Martin Mucha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 22:42:02