IDEA Maven 项目提示'java: -source 1.5 中不支持 lambda 表达式' 解决方法
IDEA Maven 项目提示'java: -source 1.5 中不支持 lambda 表达式' 解决方法
在 IDEA 中使用 Maven 创建的 Java 项目时,可能会遇到'java: -source 1.5 中不支持 lambda 表达式'的错误,这通常是因为 Maven 项目的编译器级别没有更新到 Java 1.8。
解决方法:
-
检查 Maven Compiler Plugin 配置: 在
pom.xml文件的<build>节点中添加以下配置,确保编译器级别为 1.8。<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> -
添加全局编译器配置: 如果以上配置仍然无效,可以在
pom.xml文件的<properties>节点中添加以下配置。<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> -
重新加载项目和清理目标目录: 如果以上步骤仍然无法解决问题,尝试重新加载项目或清理项目的
target目录。
注意:
- 确保你的 JDK 版本为 1.8 或更高版本。
- 确保你的 Maven 版本足够新,以支持 Java 1.8 的编译。
通过以上步骤,你应该能够解决 IDEA Maven 项目中出现的'java: -source 1.5 中不支持 lambda 表达式'的错误。
原文地址: https://www.cveoy.top/t/topic/n5nu 著作权归作者所有。请勿转载和采集!