使用 IntelliJ IDEA 进行编译的时候提示 Java 的支持 Level 不够

错误提示的信息如下:

By default, the Java language level is set to 5 which is not supported by the current Java version. Update the language level to 6+.Update source level in codebank

 

 

问题和原因

这是因为很有可能在你的 maven 配置 POM 的时候的编译插件 maven-compiler-plugin 的版本。

通常这个插件的默认版本都比较低。

如果你使用的是 3.7.0 的话,那么默认使用的是 Java 1.5 的 Level。

如果你修改使用最新的 3.8.1 的话,那么将会默认使用 1.8 的 Level。

目前,我们应该会使用 JDK 8 或者 11,因此你需要手动进行一下设置。

设置有 2 个方法。

第一个方法就是添加下面的参数到属性中。

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

第二个方法就是直接指派到插件的 config 配置中。

如下面的配置参数。

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

JDK 9 及其后续版本

maven-compiler-plugin 插件的 3.6 后续版本开始,添加了一个 release 的配置。

如果你使用 JDK 11 的话,你可以使用下面的配置。

<plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>

使用上面的配置结果将会能够更好的适配 JDK 11 版本。

https://www.ossez.com/t/intellij-idea-java-level/13436

posted @   huyuchengus  阅读(307)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2018-04-25 Confluence 6 用户宏示例 - Formatted Panel
2018-04-25 Confluence 6 用户宏示例 - Color and Size
2018-04-25 Confluence 6 用户宏示例 - NoPrint
2018-04-25 Confluence 6 用户宏示例 - Hello World
2018-04-25 Confluence 6 用户宏最佳实践
2018-04-25 Confluence 6 编辑和删除用户宏
2018-04-25 Confluence 6 创建一个用户宏
点击右上角即可分享
微信分享提示