Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

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

Java 11 : Error:java: invalid source release: 11 - Not sure what to do anymore

问题

你好,我已经为你完成了翻译:

你好,我已经从Java 8升级到了Java 11,无论如何都会遇到以下错误。我正在使用IntelliJ和Windows 10。

我对11所做的更改如下:

  1. 在项目结构 -> 项目中:
    Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

  2. 项目结构 -> 模块
    Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

  1. 我的编译器模块目标字节码版本在设置 -> 构建、执行、部署 -> Java编译器中也设置为了11。

我甚至将环境变量JAVA_HOME分别更改为用户变量和系统变量中的jdk-11.0.8。

当我运行java -version和javac -version时,两者都显示我安装了版本11。
当我尝试运行mvn clean package时,总是失败并显示以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project abc: Fatal error compiling: invalid target release: 11 -> [Help 1]

请帮我解决这个错误,非常感谢您的帮助!

附加说明 这是项目的pom的一部分

<plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <optimize>true</optimize>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                    <compilerArguments>
                        <parameters/>
                    </compilerArguments>
                </configuration>

我还添加了<release>11</release> <!--或 <release>10</release>-->,但问题仍然存在。

英文:

Hello so i have upgraded from java 8 to java 11 and i get this error no matter what.I am using intellij and windows 10.
What i have changed to 11:
1)In Project Structure -> Project:
Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

2)Project Structure ->Modules
Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

3)My compiler module Target bytecode version is set to 11 aswell in settings->Build,Execution,Deployment -> Java Compiler.

I even changed Both environment variables respectiveley the JAVA_HOME in user variables and JAVA_HOME in system variables to jdk-11.0.8.

When i run java -version and javac -version both show that i have version 11 installed.
When i try running a mvn clean package it always fails with this error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project abc: Fatal error compiling: invalid
target release: 11 -> [Help 1]

Please help me fix the error,
Any help would be greatly appreciated !

L.EThis is part of the project pom

<plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <optimize>true</optimize>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                    <compilerArguments>
                        <parameters/>
                    </compilerArguments>
                </configuration>

I have also added <release>11</release> <!--or <release>10</release>--> to it but same issue remains.

答案1

得分: 48

以下是翻译好的内容:

IntelliJ IDEA 2021.1.3(社区版)

如果您正在使用Gradle构建工具:

文件 | 设置 | 构建、执行、部署 | 构建工具 | Gradle

选择您的项目,然后选择Gradle JVM版本11。
Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

英文:

IntelliJ IDEA 2021.1.3 (Community Edition)

If you are using Gradle build tool:

File | Settings | Build, Execution, Deployment | Build Tools | Gradle

Choose your project and choose Gradle JVM version 11.
Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

答案2

得分: 10

请在IntelliJ中检查您的JDK 11设置!尽管项目SDK被称为11,但它仍然显示您的java版本为1.8.161。从这个信息来看,似乎您的新JDK 11仍然指向您的旧1.8安装,而旧版本不支持版本11。

英文:

Please check your JDK 11 Setup in IntelliJ! Even though the project SDK is called 11, it still says that your java-version is 1.8.161. Judging from this it looks like your new jdk 11 still points to your old 1.8 installation which does not now about version 11 yet.

答案3

得分: 2

对我来说,解决方法是设置JAVA_HOME变量。尽管你提到过它作为你尝试过的解决方案,但很容易忽略它。我正在处理不同的项目,并且在一些项目中使用java 8,在另一些项目中使用java 11。我不得不在这些版本之间切换以使其正常工作。

Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

英文:

For me the solution was setting the JAVA_HOME var. Though you mentioned it as a solution you tried it's easy to read over it. I'm working with different projects and using java 8 for a few and java 11 for another. I had to switch between these versions to get this to work

Java 11:错误:java:无效的源发布:11 – 不确定还要做什么。

答案4

得分: -5

请检查 pom 版本是否指向11或8。

英文:

Please check pom version point to 11 or 8

huangapple
  • 本文由 发表于 2020年9月28日 14:01:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64096720.html
匿名

发表评论

匿名网友

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

确定