使用idea进行maven install老是报-source 1.5 中不支持 lambda 表达式

1、idea的maven设置

2、JDK配置

3、项目模块配置

以上设置均正常,但是在执行maven的install还是报错:-source 1.5 中不支持 lambda 表达式

另外发现在执行这个步骤,原来的jdk设置会还原成1.5版本

因为代码里面使用了高版本JDK才有的表达式

所以打包肯定是要报错

所以查询资料后发现

原来 Maven Compiler 插件默认会加 -source 1.5 及 -target 1.5 参数来编译(估计是为了兼容一些比较老的 Linux 服务器操作系统,它们通常只有 JDK 5)(出自:https://www.cnblogs.com/softidea/p/6256543.html

所以在pom.xml中添加了配置

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

再重新clean(要清除原先失败的target)和install后执行OK

猜你喜欢

转载自blog.csdn.net/weixin_42499073/article/details/84067154
今日推荐