You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ 2021.2.2编译Java项目报错invalid source release: 18求助

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

Project
Modules
Java Compiler

解决方案

该报错由IntelliJ IDEA更新后自动修改了项目JDK相关配置,和实际使用的JDK 16.0.1版本不匹配导致,按以下步骤逐一核对修改即可:

  • 核对项目级别JDK配置
    打开File > Project Structure > Project页面,确认两个配置项:
    1. SDK 选项选择本地安装的JDK 16.0.1,排除IDEA自动切换为内置JDK或其他版本的可能
    2. Language level 选项选择对应JDK 16的等级,不要选17、18等更高版本
  • 核对模块级别JDK配置
    在Project Structure页面切换到Modules标签,选中Adexo模块:
    1. Sources标签下的Language level和项目级配置保持一致,为JDK 16对应等级
    2. Dependencies标签下的模块SDK也选择JDK 16.0.1
  • 核对Java编译器配置
    打开File > Settings > Build, Execution, Deployment > Compiler > Java Compiler:
    1. Project bytecode version 选择16,不要使用默认的18或其他版本
    2. 下方Per-module bytecode version列表如果存在Adexo模块的配置,将其Target bytecode version也改为16
    3. 取消勾选Use '--release' option for cross-compilation (Java 9 and later)选项,避免IDEA自动追加错误的版本参数
  • 清理缓存重启重建
    点击顶部菜单File > Invalidate Caches...,勾选Clear file system cache and local history后点击Invalidate and Restart,重启后重新构建项目即可正常编译。

内容的提问来源于stack exchange,提问作者ADEX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 17:06:03