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

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

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on 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]

上述引文中 具体为当前项目名

现场

当项目执行 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>

环境

检查项 结果
JDK 1.7
编辑器 Vscode

解决方案

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

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

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

重新编译,通过

你可能感兴趣的:(笔记,java技术,java,apache,maven)