Intellij maven项目致命错误编译:无效标志: - release

Ami*_*nul 23 java intellij-idea maven maven-compiler-plugin spring-boot

我试图从Spring-boot开始,在Intellij中使用Maven请帮助我我收到错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag: --release -> [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
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>

       <groupId>com.example</groupId>
       <artifactId>spring-rest</artifactId>
       <version>3.1.3.RELEASE</version>
       <packaging>war</packaging>

       <name>spring-rest</name>
       <description>Demo project for Spring Boot</description>

       <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>2.0.0.RELEASE</version>
           <relativePath/> <!-- lookup parent from repository -->
       </parent>

       <properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
           <java.version>1.8</java.version>
       </properties>

       <dependencies>

           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-security</artifactId>
               <version>2.0.0.RELEASE</version>
           </dependency>

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

           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-data-jpa</artifactId>
           </dependency>
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>

           <dependency>
               <groupId>org.hibernate.javax.persistence</groupId>
               <artifactId>hibernate-jpa-2.1-api</artifactId>
               <version>RELEASE</version>
           </dependency>


           <dependency>
               <groupId>mysql</groupId>
               <artifactId>mysql-connector-java</artifactId>
               <scope>runtime</scope>
           </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>

               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.7.0</version>
                   <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                       <release>8</release>
                       <verbose>true</verbose>
                   </configuration>
               </plugin>
           </plugins>
       </build>

   </project>
Run Code Online (Sandbox Code Playgroud)

Mat*_*ldi 28

在您的pom.xml文件中,只需<release>8</release>maven-compiler-plugin配置中删除标记 :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <verbose>true</verbose>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

  • 如果安装了多个 java 版本:验证您正在使用 java 9+ 版本运行 Maven:“mvn --version”。还要确保您的 IDE 使用正确的 JDK 版本。 (9认同)
  • 为我工作-谢谢-只是为了添加一个原因-看起来是为Java 9向后兼容性添加的“发布” https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#release。但是并不能很好地处理前向兼容性。 (4认同)
  • 仅供参考,一旦更改了 JAVA_HOME,就必须重新启动 Intellij。 (3认同)
  • 对……环境的最低要求。使用“--release”选项的设置是:Maven:3.6.0;JDK:9+ (2认同)

小智 20

我也遇到这个问题,检查你的JAVA_HOME环境变量。我将release的值设置为11,因为我使用的是JAVA 11。我的系统JAVA_HOME设置为java 8,将JAVA_HOME用户环境变量添加到java 11路径后,这个问题得到了解决。


Kri*_*ula 15

这与系统上运行的 JDK 版本有关。根据 maven-compiler-plugin 的文档,从 1.9 开始支持 release 标志,因此如果您使用以前(1.8 及以下)版本的 JDK,则必须从 POM 中注释/删除。

在此处检查 Maven 文档以获取 maven-compiler-plugin 的发布标记

  • 我遇到了这个问题,我忘记更改 JAVA_HOME 环境变量以指向我的 java 11 JDK。(`导出 JAVA_HOME=$(/usr/libexec/java_home -v11)` ) (2认同)

izy*_*izy 15

打开终端检查 Maven 是否使用正确的 Java 版本

跑步:mvn -v

如果您看到旧的 Java 版本,则可能是问题所在。

在 Linux 上,我建议删除 Maven,例如使用 Fedora 包管理器dnf remove maven或检查 Maven 的 PATH。

从这里下载一个: https: //maven.apache.org/download.cgi

解压下载到您的主路径,例如~/maven.

添加/编辑~/maven/bin到您的路径

重新应用.bash_profile(或重新登录)

跑步mvn -v

现在您应该在输出中看到正确的 Java 版本