【异常】java: 警告: 源发行版 11 需要目标发行版 11

写在前面

笔者遇到的问题比较极端,在阅读之前建议检查是否是项目结构中语言级别和jdk版本不匹配的问题 ❗,确认并非语言级别级别问题再阅读以下。

先说结论:🙌
idea 的【配置文件iml】 与项目中【配置】的jdk版本不一致❗

排查.iml 文件,检查LANGUAGE_LEVEL=“JDK_11” 是否与当前配置一致,不一致删除 LANGUAGE_LEVEL=“JDK_XXX”

 <component name="NameModuleRootManaget" LANGUAGE_LEVEL="JDK_11">

清理target 目录,重新运行

mvn clean

问题

事情发生在一个清晨,当我新建一个项目准备开始coding时突然记得今天的任务似乎有点似曾相识,于是我找到之前的一个项目,将其中【一整个模块整体粘贴】过来😢😢😢

项目路径

至此这个警告就出现了【java: 警告:源发行版11需要目标发行版 11】❌

一开始我并未在意,耐心调整项目结构中语言级别(就像开头提到的那样),但故事远远没有这么简单,一番修改之后我的配置如下,依然未解决问题❌

项目配置

项目sdk🧐语言级别🧐

解决😀

经过反复排查,定位到 .iml 文件✨中的这样一段配置

<component name="NameModuleRootManaget" LANGUAGE_LEVEL="JDK_11">

LANGUAGE_LEVEL 显然不对,当前【项目结构】中配置的明明是jdk_8 😢
在这里插入图片描述
将LANGUAGE_LEVEL删除,执行mvn clean 清理target 目录,重新运行,问题解决

<component name="NameModuleRootManaget">

分析

Project formats

In IntelliJ IDEA, there are two types of formats in which a project’s configuration can be stored — the file-based format and the directory-based format.

File-based format

The file-based format was the only one available in older versions of IntelliJ IDEA; now it is outdated. Projects in this format contain several files: the .ipr, .iws, and .iml files. Generally, we don’t recommend using this format unless you need to open projects in different file managers by clicking the .ipr file, or unless you need to store multiple projects in one directory.

file

Directory-based format

For the directory-based format, the IDE creates the .iml file and the .idea directory that keeps project settings. It’s the default format for projects in IntelliJ IDEA at this moment.

This format was introduced after the file-based format. Its main advantage is that it’s adjusted to store project files in Version Control Systems: the project data is split over multiple files, and merge conflicts are less likely. For more information on how to share projects in different formats, refer to How to manage projects under Version Control Systems
On macOS and Linux, the .idea directory is hidden by default. To display the directory, allow showing hidden files in your system settings.
A simple directory-based project shown in Finder

Change the project format to directory-based

From the main menu, select File | Manage IDE Settings | Save as Directory-Based Format.


JetBrains project doc原文地址

我的理解

对于项目的设置可以有两种方式去存储,分别是 基于文件的方式 和基于目录的方式,而官方并不推荐基于文件的方式,本文中提到的是基于目录的存储方式,基于目录的存储方式的最大优点就是可以用于版本控制。尽管这么说,但是idea自动生成的.gitignore 文件还是默认排除掉.idea & .iml

IntelliJ IDEA

.idea
*.iwx
*.iml
*.ipr

.iml 的优先级高于在项目结构中配置的配置,那么既然是用来存储项目结构的文件,为什么不能和手动配置的项目结构保持一致呢?
经过反复尝试得知,iml文件是由Idea自动生成,总是在你注意不到的时候生成,况且会与你的意愿相违背!

持续更新…

  • 24
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值