IDEA 使用Maven构建项目提示:Error:java: 错误: 不支持发行版本 5

IDEA 使用Maven构建项目提示:Error:java: 错误: 不支持发行版本 5

在IDEA使用Maven构建项目提示总提示 Error:java: 错误: 不支持发行版本 5,是因为Intellij IDEA用Maven来构建项目,若pom.xml没有指定版本,总是默认Language level 5 与 Java Compiler 1.5。

解决办法:

方法一(手动修改)

  • File -> Settings -> Java Compiler -> Target bytecode version = 8

  • File -> Project Structure -> Language level : 8 - Lambdas,type annotations etc

方法二(修改pom.xml):

  • 方式一:添加properties节点 (重启项目后生效)

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--修改Language level-->
        <maven.compiler.source>1.8</maven.compiler.source>
        <!--修改Java Compiler-->
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
  • 方式二:pom.xml中添加build节点

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
原文地址:https://www.cnblogs.com/fate-pc/p/13301543.html