【Java】[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile

文章描述了一个在从JDK8升级到JDK17后,使用Maven编译项目时遇到的IllegalAccessError。问题与lombok库和JDK17的不兼容有关。通过将Maven编译器的源和目标版本设置回1.8,解决了编译问题。
摘要由CSDN通过智能技术生成

原本项目是可以运行的,直到进行了一次 mvn clean ,就报如下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project <your-project-XXX>: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.Processor (in unnamed module @0x4be23f5a) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x4be23f5a -> [Help 1]

上述引文中 <your-project-XXX> 具体为当前项目名

现场

当项目执行 mvn clean 后,项目便不能启动,根据错误信息,当是编译便不能通过。

尝试使用 mvn compile 也不能正常编译 。
尝试关闭 VsCode 重新打开,依然不能正常编译。

于是检查环境 …

具体操作日志如下:

PS D:\workspace\your-project> & mvn package -f "d:\workspace\your-project\pom.xml"
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for cn.ghostcloud:your-project:jar:0.0.1
[WARNING] 'dependencies.dependency.systemPath' for com.github.magicsky:sya:jar should not point at files within the project directory, ${project.basedir}/libs/sya.jar will be unresolvable by dependent projects @ line 132, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] -------------------< cn.ghostcloud:your-project >--------------------
[INFO] Building your-project 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ your-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 2 resources
[INFO] Copying 78 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ your-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 267 source files to d:\workspace\your-project\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.396 s
[INFO] Finished at: 2024-01-04T11:21:53+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project your-project: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.Processor (in unnamed module @0x4be23f5a) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x4be23f5a -> [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] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
PS D:\workspace\your-project> java -version
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)
PS D:\workspace\your-project>

环境

检查项结果
JDK17
编辑器Vscode

解决方案

JDK 17 是最近升级了 Vscode 后换了的,以前是 JDK 8 。因此猜想是 JDK 版本问题,且项目中有一些 eclipse 插件中的 jar ,它们是 JDK8 编译的。

于是在 pom.xml 中进行如下设置

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

重新编译,通过

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值