IntelliJ:错误:java:不支持发布版本 10
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52788743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ: Error: java: release version 10 not supported
提问by MiguelMunoz
In IntelliJ, I'm getting this strange error message when I try to build from the build menu: Error: java: release version 10 not supported
在 IntelliJ 中,当我尝试从构建菜单构建时收到此奇怪的错误消息:错误:java:不支持发布版本 10
I don't understand this, since in Project Structure, I have these settings set: Project SDK: 9.0 Project Language Level: SDK Default Module Language Level: Project Default (both modules)
我不明白这一点,因为在项目结构中,我设置了以下设置:项目 SDK:9.0 项目语言级别:SDK 默认模块语言级别:项目默认值(两个模块)
In my pom.xml files, I have these properties set in both modules:
在我的 pom.xml 文件中,我在两个模块中都设置了这些属性:
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
I have no idea why it's trying to use JDK 10 for anything, but I still get that message. I'd be happy to use JDK10, but my project doesn't work in that version, so I'm going back to see which versions it works in. I have SDKs installed for version 1.4 through 10 I've also tried building using JDK 1.8, but I get a slightly different error message: Error: java: invalid target release: 10 I've found that I can build from the command line using JDK 9, but I need to build from my IDE. Can anyone tell me how to build my project using JDK 1.9 or 1.8? Thanks.
我不知道为什么它试图将 JDK 10 用于任何事情,但我仍然收到该消息。我很乐意使用 JDK10,但我的项目在那个版本中不起作用,所以我要回去看看它在哪些版本中工作。我安装了 1.4 到 10 版的 SDK 我也尝试使用构建JDK 1.8,但我收到一个稍微不同的错误消息:错误:java:无效目标版本:10 我发现我可以使用 JDK 9 从命令行构建,但我需要从我的 IDE 构建。谁能告诉我如何使用 JDK 1.9 或 1.8 构建我的项目?谢谢。
采纳答案by MiguelMunoz
I just figured it out. I also needed to adjust the version in the maven-compiler-plugin. I'm using version 3.8.0. I needed to change this value:
我只是想通了。我还需要调整 maven-compiler-plugin 中的版本。我正在使用 3.8.0 版。我需要更改此值:
<release>10</release>
Here's where I found it:
这是我找到它的地方:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release> <!-- This was the problem. -->
</configuration>
...
回答by Yihe
I got a similar error but did not use Maven.
我遇到了类似的错误,但没有使用 Maven。
Solved it by updating the IntelliJ configuration:
通过更新 IntelliJ 配置解决了这个问题:
- File -> Settings-> Build, Execution, Development -> Compiler -> Java Compiler
- update
Project bytecode version
to 8
- 文件 -> 设置 -> 构建、执行、开发 -> 编译器 -> Java 编译器
- 更新
Project bytecode version
到 8
回答by Andrushenko Alexander
Probably your IntelliJ IDEA previously used Java 8. Starting from java 9 Java, instead of having 2 parts, jdk and jre, Java has only one, the jdk. I have got the same error message when I switched from java 8 to java 11. So you have to switch the IntelliJ IDEA to the new Java version.
可能您的 IntelliJ IDEA 以前使用过 Java 8。从 Java 9 开始,Java 不再有 2 个部分 jdk 和 jre,而是只有一个,即 jdk。当我从 java 8 切换到 java 11 时,我收到了同样的错误消息。所以你必须将 IntelliJ IDEA 切换到新的 Java 版本。
Open the Project Structure(Ctrl+Shift+Alt+S)
打开项目结构( Ctrl+ Shift+ Alt+ S)
Alternatively, from the IntelliJ IDEA menu: File -> Project Structure -> Project
或者,从 IntelliJ IDEA 菜单:文件 -> 项目结构 -> 项目
Define the new jdk. Recompile the project.
定义新的 jdk。重新编译项目。
This has worked for me.
这对我有用。
回答by Magnilex
The most upvoted answer really helped me. However, for me the problem wasn't the Project bytecode version. Instead, my Maven module was marked with Target bytecode version 1.5, see picture below.
最受好评的答案真的帮助了我。但是,对我来说,问题不在于Project bytecode version。相反,我的 Maven 模块被标记为Target bytecode version 1.5,见下图。
Just clicking the row and removing it fixed the problem:
只需单击该行并将其删除即可解决问题:
- File -> Settings-> Build, Execution, Development -> Compiler -> Java Compiler
- Delete any Per-module bytecode versions in the list, which override the project bytecode version.
- 文件 -> 设置 -> 构建、执行、开发 -> 编译器 -> Java 编译器
- 删除列表中的任何 Per-module 字节码版本,这会覆盖项目字节码版本。
回答by Samer Yousef
I got this message Java error version 12 is not supported. and I am using 11.
我收到此消息 Java 错误版本 12 不受支持。我正在使用 11。
How did I managed to solve this issue? Go to File --> Project Structure --> Projectand Change the Project Language Level to the version that you have and click and apply.
我是如何设法解决这个问题的?转到文件 --> 项目结构 --> 项目并将项目语言级别更改为您拥有的版本,然后单击并应用。
回答by Weijing Jay Lin
For someone just update their maven file in properties section, please make sure if you click the refresh on the IDE maven tool in order to trigger the prop settings.
对于只是在属性部分更新他们的 maven 文件的人,请确保您是否单击 IDE maven 工具上的刷新以触发道具设置。
Step 1.
第1步。
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
Step 2. (very important!!!)
第 2 步。(非常重要!!!)
Click "refresh" icon on IntelliJ Maven tool bar.
单击 IntelliJ Maven 工具栏上的“刷新”图标。
回答by smilesr
I had similar issue except that the error was "release version 5 not supported. " I tried all of the above and other proposed solutions but nothing worked, except putting following xml into the pom.xml file:
我遇到了类似的问题,只是错误是“不支持发布版本 5。”我尝试了上述所有和其他建议的解决方案,但没有任何效果,除了将以下 xml 放入 pom.xml 文件中:
<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Code comes from: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
代码来自:https: //maven.apache.org/guides/getting-started/maven-in-five-minutes.html
After putting this code in pom.xml, make sure to Import Changes or Enable Auto-Import for the Maven project:
将此代码放入 pom.xml 后,确保为 Maven 项目导入更改或启用自动导入:
回答by prisar
putting below code in pom.xml works.
将下面的代码放在 pom.xml 中有效。
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.release>11</maven.compiler.release>
回答by Marcus
I solved this by going to Maven settings;
我通过转到 Maven 设置解决了这个问题;
Step 1. either going through;
步骤 1. 要么通过;
- monkey wrench icon in maven (jump to step 2)
- File - Settings or Ctrl+Alt+S
- maven 中的猴子扳手图标(跳到第 2 步)
- 文件-设置或Ctrl+ Alt+S
Step 2. Go to Build, Execution, Deployment - Maven - Importing: JDK for importer(at the bottom)
步骤 2. 转到构建、执行、部署 - Maven - 导入:导入器的JDK(底部)
回答by NaKib
At first, Put this code in your pom.xml
首先,将此代码放在您的 pom.xml 中
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>Current Latest Version of Maven e.g. 3.8.1</version>
<configuration>
<target>Java Version installed in your system e.g. 13</target>
<source>Java Version installed in your system e.g. 13</source>
<release>Java Version installed in your system e.g. 13</release>
</configuration>
</plugin>
</plugins>
</build>
And Also Go to File> Settings > Build, Execution, Deployment > Compiler> Java Compiler and change "Project bytecode version" to Java Version installed in your system e.g. 13
并转到文件> 设置> 构建、执行、部署> 编译器> Java 编译器并将“项目字节码版本”更改为系统中安装的 Java 版本,例如 13