美文网首页
Maven 指定编译language level

Maven 指定编译language level

作者: steamed_bun | 来源:发表于2020-03-23 20:36 被阅读0次

    问题:在idea中遇到如下问题

    //-source 1.5 中不支持 diamond 运算符   (请使用 -source 7 或更高版本以启用 diamond 运算符)
    Diamond types are not supported at language level '5'
    //-source 1.5 中不支持 lambda 表达式(请使用 -source 8 或更高版本以启用 lambda 表达式)
    Lambda expressions are not supported at language level '5'
    

    解决方法:
    1、File -> Project Structure -> Modules -> Sources -> Language level -> 如果是jdk1.8 就是 8 - Lambdas,type annotations etc
    注:这样idea就没有报错了,但是编译的时候还会报错Error:java: Compilation failed: internal java compiler error
    2、pom文件加入,指定maven-compiler-plugin的版本号,尤其是-source-target

    <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>
    

    maven-compiler-plugin最新的是3.8.1,里面写了默认的-source-target是1.6,强烈建议更改-source-target的默认值

    相关文章

      网友评论

          本文标题:Maven 指定编译language level

          本文链接:https://www.haomeiwen.com/subject/rjowyhtx.html