如何避免IntelliJ重置语言级别? [英] How to avoid IntelliJ to reset language level?
问题描述
我对此感到很麻烦,这个问题已经在本网站上得到过多次回答.
I am having troubles with this which have been answered dusin of times on this site.
我对这个问题的看法有些不同.我有一个项目可以使用maven 3.5.x和Java版本10(在maven-compiler-plugin中配置)很好地构建 查看IntelliJ的项目结构时,所有模块的语言级别均为10(但项目设置为语言级别6,并且在项目结构中选择的sdk为1.8 ...
My take on the problem is a bit different. I have a project which builds fine using maven 3.5.x and java release 10 (configured in the maven-compiler-plugin) When looking in IntelliJ's project structure, all modules have language level 10 (but the projects settings is language level 6 and the chosen sdk in the project structure is 1.8...
但是,即使我将sdk更改为java 10并将项目语言级别更改为10,仍然会发生以下粘贴的错误... ????
However, even if I change the sdk to java 10 and the projects language level to 10, the error pasted below still occurs... ????
我的IntelliJ版本:IntelliJ IDEA 2018.2.5
My IntelliJ version: IntelliJ IDEA 2018.2.5
要重现此错误:
-
从版本控制(GIT)中检出
Check out from version control (GIT)
GitHub: https://github.com/jactor-rises/jactor -rises.git
尝试在IntelliJ中构建它:
Try to build it within IntelliJ:
信息:java:编译模块时发生错误 'jactor-commons'信息:javac 10.0.1用于编译Java 来源信息:29/10/2018,21:31-编译完成1 错误和0警告在4 s 777 ms中错误:java:发行版本5不 支持
Information:java: Errors occurred while compiling module 'jactor-commons' Information:javac 10.0.1 was used to compile java sources Information:29/10/2018, 21:31 - Compilation completed with 1 error and 0 warnings in 4 s 777 ms Error:java: release version 5 not supported
推荐答案
您可以通过以下设置将要执行的模块的Java编译器版本更新为使用Java版本10:
You can update the Java Compiler version of your module to be executed to use Java version 10 with the following settings :
构建,执行,部署=>编译器=> Java编译器=>更新目标字节码版本
Build, Execution, Deployment => Compiler => Java Compiler => Update Target Bytecode version
在上图中,您会注意到模块 guice 和 hbase 默认使用Java版本5,而我将其他模块更新为使用Java版本11,是在使用JDK 11编译和执行它们时效果很好.
In the image above you can notice that the modules guice and hbase are defaulting to use Java version 5 while I've updated the others to use Java version 11 which is when compiling and executing them with JDK 11 works just fine.
这篇关于如何避免IntelliJ重置语言级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!