简体   繁体   English

如何避免 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.我遇到了这个问题,这个问题已经在这个网站上回答了多次。

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...我有一个使用 maven 3.5.x 和 java 版本 10 构建良好的项目(在 maven-compiler-plugin 中配置)查看 IntelliJ 的项目结构时,所有模块的语言级别为 10(但项目设置为语言级别 6,并且在项目结构中选择的 sdk 是 1.8 ...

However, even if I change the sdk to java 10 and the projects language level to 10, the error pasted below still occurs... ????但是,即使我将sdk更改为java 10并将项目语言级别更改为10,仍然会出现下面粘贴的错误...... ????

My IntelliJ version: IntelliJ IDEA 2018.2.5我的IntelliJ版本:IntelliJ IDEA 2018.2.5

To reproduce this error:要重现此错误:

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:编译模块 'jactor-commons' 时出错 信息:javac 10.0.1 用于编译 java 源 信息:29/10/2018, 21:31 - 编译完成,4 秒内出现 1 个错误和 0 个警告 777 ms 错误:java:不支持发布版本 5

You can update the Java Compiler version of your module to be executed to use Java version 10 with the following settings :您可以更新要执行的模块的 Java 编译器版本,以使用具有以下设置的 Java 版本 10:

Build, Execution, Deployment => Compiler => Java Compiler => Update Target Bytecode version构建、执行、部署 => 编译器 => Java 编译器 => 更新目标字节码版本

在此处输入图片说明

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.在上图中,您可以注意到模块guicehbase默认使用 Java 版本 5,而我已将其他模块更新为使用 Java 版本 11,这在使用 JDK 11 编译和执行它们时可以正常工作。

I just update the pom.xml and it works for me.我只是更新pom.xml ,它对我pom.xml

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>1.11</source>
        <target>1.11</target>
        <release>11</release>
    </configuration>
</plugin>

In my case, I had to update value in pom.xml AND refreshing maven.就我而言,我不得不更新值pom.xml爽口行家。

<properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
</properties>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM