java - Maven 未使用 Java 11 - 编译 : invalid target release: 11 的 fatal error

标签 java spring spring-boot maven

我正在尝试使用 Java 11 编译我的项目。
当我尝试使用 Java 8 作为 pom.xml 中的 Java 版本运行应用程序时,它工作正常。但是当我尝试使用 Java 11 运行它时,它会引发错误。

Fatal error compiling: invalid target release: 11


我尝试以各种方式修复它,例如更改环境变量、更新路径以及将 %JAVA_HOME% 指向 Java 11。
我电脑上的命令和结果如下:
> java -version
java version "11.0.8" 2020-07-14 LTS
> echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.8
我正在使用 IntelliJ IDEA 并按照 this 中的建议进行了必要的更改教程。
我的 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.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>businessapplication-6963d</projectId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

当我检查 Maven 版本时,它显示 JDK 1.8 作为 Java 版本:
mvn --version
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_241\jre
如何将 Maven 指向 Java 11?或者,如果这不是问题,如何解决这个问题?我不认为这个问题与 invalid target release: 1.7 重复,因为我已经实现了该线程中提供的解决方案。
构建项目后出错
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [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
Path Environment Variable is :- 
C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;
C:\Delhi 2.0\apache-maven-3.6.1\bin;
C:\Program Files\Java\jdk-11.0.8\bin;C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files\Git\cmd;D:\Flutter\flutter\flutter\bin;
C:\Users\Infinity97\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin;
C:\Users\Infinity97\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2\bin;
H:\apache-maven-3.6.3\bin;
C:\Program Files\PostgreSQL\12\bin;
C:\Program Files\PostgreSQL\12\lib;
C:\Program Files\Docker Toolbox

最佳答案

好像你有 JAVA_HOME设置在您的 mvn.bat .它可能指向旧版本的 Java(即在您的情况下为 8)。set JAVA_HOME=C:\path\to\jdk11在调用 maven 之前尝试在第一行使用它。

关于java - Maven 未使用 Java 11 - 编译 : invalid target release: 11 的 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63154787/

相关文章:

java - Spring Boot @RestController 端点和 Spring Data Rest 投影

java - Spring Boot 不绑定(bind)到 Tomcat 端口

java - 如何使用 Material Design 更改操作栏文本颜色?

Java,将数据库连接传递到不同的类中。

java - 制作 Swing Logo 测验

java - 在 Hibernate JPA2 上使用唯一约束

java - 身份验证在 Spring 中不起作用

java - HTTP 400 的 Spring MVC 自定义消息

java - Spring + Hibernate DAO 作为泛型类

spring-boot - spring boot : same feign client interface, 具有不同属性的多个实例