JDK21与lombok插件的兼容性问题

最近在搭建一个demo项目。

基于老项目来配置,结果发生了一些错误。

java 复制代码
lombok 方法引用无效  找不到符号

[ERROR] Failed to execute goal 
       org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile)
        on project rc-platform: Resolution of annotationProcessorPath dependencies failed:
         For artifact {org.projectlombok:lombok:null:jar}: The version cannot be empty. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch
        to enable full debug logging.
[ERROR] 

[ERROR] Failed to execute goal
        org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile)
         on project rc-platform: Fatal error compiling: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member
          field 'com.sun.tools.javac.tree.JCTree qualid' -> [Help 1]
[ERROR] 

解决办法:

使用最新的 lombok 版本.

例如:

xml 复制代码
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.42</version>
            <optional>true</optional>
        </dependency>
    </dependencies>



    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.42</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <!--  在SpringBoot 的打包阶段不需要lombok-->
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

按照 stackoverflow 的说法:

The culprit is Lombok. The minimal Lombok version compatible with JDK 21 is 1.18.30.

链接:

https://stackoverflow.com/questions/77171270/compilation-error-after-upgrading-to-jdk-21-nosuchfielderror-jcimport-does-n

相关推荐
vx1_Biye_Design2 小时前
基于Spring Boot+Vue的学生管理系统设计与实现-计算机毕业设计源码46223
java·vue.js·spring boot·spring·eclipse·tomcat·maven
m0_5613596718 小时前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
HAPPY酷18 小时前
构造与析构:C++ 中对象的温柔生灭
java·jvm·c++
海心焱21 小时前
从零开始构建 AI 插件生态:深挖 MCP 如何打破 LLM 与本地数据的连接壁垒
jvm·人工智能·oracle
hello 早上好1 天前
04_JVM 类加载子系统与内存结构
jvm
qq_336313931 天前
javaweb-maven单元测试
java·开发语言·maven
Serene_Dream1 天前
Java 垃圾收集器
java·jvm·面试·gc
weisian1511 天前
JVM--6-深入JVM栈内存:方法调用的执行舞台
jvm·栈帧·栈内存
Serene_Dream1 天前
Java 内存区域
java·jvm
star12581 天前
数据分析与科学计算
jvm·数据库·python