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

相关推荐
Oueii21 小时前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
爱丽_1 天前
JVM 类加载机制:双亲委派模型、打破场景与排查思路
jvm
2401_831824961 天前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf1 天前
Python日志记录(Logging)最佳实践
jvm·数据库·python
2401_851272991 天前
实战:用Python分析某电商销售数据
jvm·数据库·python
2401_857918291 天前
用Python和Twilio构建短信通知系统
jvm·数据库·python
樹JUMP1 天前
使用Docker容器化你的Python应用
jvm·数据库·python
2501_945423541 天前
使用Fabric自动化你的部署流程
jvm·数据库·python
2401_846341651 天前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
2401_831824961 天前
编写一个Python脚本自动下载壁纸
jvm·数据库·python