笔者遇到的问题比较极端,在阅读之前建议检查是否是项目结构中语言级别和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.
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.
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自动生成,总是在你注意不到的时候生成,况且会与你的意愿相违背!
持续更新…