Maven编译插件在执行mvn package或mvn clean install时出错。

huangapple go评论72阅读模式
英文:

Maven compiler plugin error compiling, while executing mvn package or mvn clean install

问题

我从github上克隆了一个项目,该项目使用了java 8spring bootmysql

所以我做的第一件事是在intellij中配置jdk,我有openjdk 1715,所以我选择了v15,我运行了应用程序,

它正常运行,但当我尝试运行mvn package时出现了以下错误:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project platform: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x16a9eb2e) 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 @0x16a9eb2e

这是pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ezlearning</groupId>
    <artifactId>platform</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>platform</name>
    <description>Ez learning platform</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- Thymeleaf Spring Security -->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- MySql dependency -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- Database versioning -->
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <!-- Spring Boot Security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

</project>

我尝试检查了我的机器上的Maven版本,它是3.8.5,所以我不知道问题是否是因为项目的Maven编译器版本是3.8.1,而我的是3.8.5,我是个新手,所以我真的没有解决方案,我只是尝试将这个应用程序容器化,所以我正在构建jar文件。

英文:

I cloned a project from github, the projects made using java 8, spring boot, mysql,

so the first thing I did was configuring the jdk in intellij, I have openjdk 17 , and 15 , so I chose v15 , I run the application,

it's running fine, and when I tried to make mvn package this error came out:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project platform: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x16a9eb2e) 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 @0x16a9eb2e 

This is the pom.xml file:

type h&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.1.8.RELEASE&lt;/version&gt;
&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;groupId&gt;com.ezlearning&lt;/groupId&gt;
&lt;artifactId&gt;platform&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;platform&lt;/name&gt;
&lt;description&gt;Ez learning platform&lt;/description&gt;
&lt;properties&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Thymeleaf Spring Security --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
&lt;artifactId&gt;thymeleaf-extras-springsecurity5&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.h2database&lt;/groupId&gt;
&lt;artifactId&gt;h2&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- MySql dependency --&gt;
&lt;dependency&gt;
&lt;groupId&gt;mysql&lt;/groupId&gt;
&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Database versioning --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.flywaydb&lt;/groupId&gt;
&lt;artifactId&gt;flyway-core&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Spring Boot Security --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;
```

Screenshots


  1. Maven编译插件在执行mvn package或mvn clean install时出错。

  1. Maven编译插件在执行mvn package或mvn clean install时出错。

  1. Maven编译插件在执行mvn package或mvn clean install时出错。

I tried to check the Maven version in my machine , and it's 3.8.5, so I don't know if the problem is because the project's Maven compiler is 3.8.1 and mine is 3.8.5, I'm a newbie so I really dont have a solution for this , I'm just trying to containerize this application that's why I'm building the jar file.

答案1

得分: 2

在你的 pom.xml 文件中,将以下内容添加到 properties 部分:

    <properties>
        <java.version>1.8</java.version>
        <!-- START ADD 20230219 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- END ADD 20230219 -->
    </properties>

在依赖项 org.projectlombok 中,添加版本号:

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <optional>true</optional>
        </dependency>

我已经测试过,在命令行或者在 IDEA IDE 中都可以正常工作。

其他答案可能在命令行中可以正常工作,但在 IDEA IDE 中会失败。

例如:在命令行中可以正常工作,但在 IDEA IDE 中会失败。

我进行了测试,在 IDEA IDE 中没有得到良好的答案。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <fork>true</fork>
        <compilerArgs>
            <arg>--enable-preview</arg>
            <arg>-Xlint:all</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
            <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
        </compilerArgs>
        <!--for unmappable characters in classes-->
        <encoding>UTF-8</encoding>
        <showDeprecation>true</showDeprecation>
        <showWarnings>true</showWarnings>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.20</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>
英文:

in your pom.xml , properties, add these:

    &lt;properties&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;!-- START ADD 20230219 --&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
&lt;!-- END ADD 20230219 --&gt;
&lt;/properties&gt;

in dependency org.projectlombok , add version

        &lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;version&gt;1.18.20&lt;/version&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;

I already test OK, in command line or in IDEA IDE.


Other answer maybe can OK in command line , but fail in IDEA IDE.

like this: can OK in command line , but fail in IDEA IDE.

I am test, not good answer in IDEA IDE.

&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.1&lt;/version&gt;
&lt;configuration&gt;
&lt;source&gt;1.8&lt;/source&gt;
&lt;target&gt;1.8&lt;/target&gt;
&lt;fork&gt;true&lt;/fork&gt;
&lt;compilerArgs&gt;
&lt;arg&gt;--enable-preview&lt;/arg&gt;
&lt;arg&gt;-Xlint:all&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED&lt;/arg&gt;
&lt;arg&gt;-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED&lt;/arg&gt;
&lt;/compilerArgs&gt;
&lt;!--for unmappable characters in classes--&gt;
&lt;encoding&gt;UTF-8&lt;/encoding&gt;
&lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
&lt;showWarnings&gt;true&lt;/showWarnings&gt;
&lt;annotationProcessorPaths&gt;
&lt;path&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;version&gt;1.18.20&lt;/version&gt;
&lt;/path&gt;
&lt;/annotationProcessorPaths&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2023年2月19日 09:08:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定