IntelliJ运行Spring Boot报错java: invalid source release:15,已设Java11求解决
解决Java: invalid source release: 15错误(已配置Java11但编译失败)
以下是针对性的排查和解决步骤:
1. 完善Maven编译器插件配置
仅在<properties>中指定java.version可能不够,部分Spring Boot版本或Maven环境会默认使用更高的JDK版本编译。需要在pom.xml中显式配置maven-compiler-plugin,强制指定源码和目标版本:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <!-- 使用适配的插件版本即可 --> <configuration> <source>${java.version}</source> <target>${java.version}</target> <release>${java.version}</release> <!-- Java 9+推荐使用release参数统一管控版本 --> </configuration> </plugin> </plugins> </build>
修改后执行mvn clean compile验证编译是否正常。
2. 检查IntelliJ的Run/Debug配置
- 打开
Run -> Edit Configurations - 找到你的Spring Boot应用配置,切换到
Configuration标签页 - 确认
JRE选项选择的是corretto-11,而非其他JDK版本
3. 核对IntelliJ全局编译器设置
- 打开
File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler - 确认
Project bytecode version设置为11 - 检查下方模块列表中
spring_chat的Target bytecode version是否为11,若不一致则手动修改
4. 清理IntelliJ缓存并重启
缓存冲突可能导致配置不生效:
- 执行
File -> Invalidate Caches... - 选择
Invalidate and Restart,等待IDE重启后重新编译项目
内容的提问来源于stack exchange,提问作者densal03
相关产品推荐
相关产品推荐

