【问题标题】:IntelliJ 2021.2.2 gives error 'java: error: invalid source release: 18' when compiling programIntelliJ 2021.2.2 在编译程序时给出错误“java:错误:无效的源版本:18”
【发布时间】:2021-09-30 20:12:31
【问题描述】:

我在这里查看了很多答案,但没有发现任何有用的东西。我使用的是 java 版本 16.0.1 我的程序不使用 maven 或 gradle。该程序运行良好,直到我今天早些时候更新了我的 ij。

完全错误:

    Executing pre-compile tasks...
    Loading Ant configuration...
    Running Ant tasks...
    Running 'before' tasks
    Checking sources
    Parsing java... [Adexo]
    java: error: invalid source release: 18
    Checking dependencies... [Adexo]
    Dependency analysis found 0 affected files
    Errors occurred while compiling module 'Adexo'
    javac 11 was used to compile java sources
    Finished, saving caches...
    Module 'Adexo' was fully rebuilt due to project configuration/dependencies changes
    Compilation failed: errors: 1; warnings: 0
    Executing post-compile tasks...
    Loading Ant configuration...
    Running Ant tasks...
    Synchronizing output directories...

    30.9.2021 22:34 - Build completed with 1 error and 0 warnings in 3 sec, 279 ms

以下是 .idea 和 .iml 文件中的文件:https://1drv.ms/u/s!AoGu278qdPOWgm-D3ns61-gqA4Ts?e=OWg0NB

如果您需要更多信息,请告知(:

【问题讨论】:

  • 请分享项目文件(.idea 目录 + *.iml 压缩文件)。
  • 我现在已经添加了。
  • @ADEX 我没有看到项目文件的编辑。

标签: java intellij-idea javac


【解决方案1】:

.idea/misc.xml 由于某种原因指定了错误的语言级别 (JDK_X):

<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="16" project-jdk-type="JavaSDK">

关闭项目,将languageLevel更改为16,看看是否有帮助。

有一个related bug reported,但它应该在 IntelliJ IDEA 2020.2 及更高版本中修复。可能是回归。

【讨论】:

    猜你喜欢
    • 2017-04-02
    • 2018-02-27
    • 2019-06-06
    • 2017-10-29
    • 2021-03-08
    • 2021-07-23
    • 2015-06-14
    • 2019-06-05
    相关资源
    最近更新 更多