maven编译报错 -source 1.5 中不支持 lambda 表达式
在用maven编译项目是由于项目中用了jdk 1.8, 编译是报错 -source 1.5 中不支持 lambda 表达式,Google找到这篇解决方案,记录一下:
编译时报如下错误:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] AAA\.jenkins\workspace\BBB\CCC.java:[73,46] 错误: -source 1.5 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
[ERROR] AAA\.jenkins\workspace\BBB\DDD.java:[38,33] 错误: -source 1.5 中不支持 lambda 表达式
[ERROR] (请使用 -source 8 或更高版本以启用 lambda 表达式)
奇怪的是我的 Jenkins 构建机器上只安装了 JDK 8,为什么还会说不支持 diamond 和 lambda 呢?在 Google 大神的指引下,在 Maven Compiler 插件介绍 里面找到了答案:Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with.
原来 Maven Compiler 插件默认会加 -source 1.5 及 -target 1.5 参数来编译(估计是为了兼容一些比较老的 Linux 服务器操作系统,它们通常只有 JDK 5),而我们的代码里使用了 JDK 7/8 的语法。解决办法在这里:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
http://blog.csdn.net/kai161/article/details/50379418
Setting the -source and -target of the Java Compiler
Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.
For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
or configure the plugin directly:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE or use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs. In the same way, setting the sourceoption does not guarantee that your code actually compiles on a JDK with the specified version. To compile your code with a specific JDK version, different than the one used to launch Maven, refer to the Compile Using A Different JDK example.
http://maven.apache.org/components/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
maven编译报错 -source 1.5 中不支持 lambda 表达式的更多相关文章
- maven编译报错 -source 1.5 中不支持 lambda 表达式(转)
原文链接:http://blog.csdn.net/kai161/article/details/50379418 在用maven编译项目是由于项目中用了jdk 1.8, 编译是报错 -source ...
- maven编译报错 -source 1.7 中不支持 lambda 表达式
Maven项目编译失败: [ERROR] COMPILATION ERROR : [INFO] ---------------------------------------------------- ...
- 【Maven】Maven-maven编译报错 -source 1.5 中不支持 lambda 表达式
Maven-maven编译报错 -source 1.5 中不支持 lambda 表达式 maven lambda_百度搜索 maven编译报错 -source 1.5 中不支持 lambda 表达式 ...
- maven编译报错 -source 1.5 中不支持 lambda(或diamond) 表达式,编码 UTF-8 的不可映射字符
在用maven编译项目是由于项目中用了jdk 1.8, 编译是报错 -source 1.5 中不支持 lambda 表达式. 错误原因: Maven Compiler 插件默认会加 -source ...
- IDEA无法编译java8的lambda表达式提示Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式
在idea中新建了一个java8的项目,但是写lambda表达式提示语法错误,提示如下错误信息: Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式 (请 ...
- IDEA中打包Spark项目提示Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式
在idea中新建了一Spark的项目,在做项目的编译打包的时候,提示如下错误信息: Error:(, ) java: -source 1.5 中不支持 lambda 表达式 (请使用 -source ...
- maven 报错 -source 1.5 中不支持 diamond 运算符
maven 执行install 报-source 1.5 中不支持 diamond 运算符 解决办法, 指定编译版本 <build> <plugins> <plugin& ...
- maven编译报错 错误: -source 1.5 中不支持 lambda 表达式
ji与基于maven的工程java应用程序非web应用的 参考这个https://www.cnblogs.com/softidea/p/6256543.html 但是java应用里边是没有这个配置的, ...
- 解决maven打jar包报错 source 1.3 中不支持
问题:maven在进行打包时,报 '请使用-source 5 或者更高版本以启用XX'的信息并导致打包失败. 原因:maven默认的编译插件的java版本较低,导致其不支持例如泛型,注解等用法. 解决 ...
随机推荐
- css样式思维导图
- Alpha 测试
活动助手Alpha--测试篇 测试分工 人员 分工 测试 牛姐 Android开发/ui设计 功能测试 橙汁 Android开发 功能测试 洪 数据库开发 数据库结构测试 佳凯 数据库设计与开发 接口 ...
- RUDP之三 —— Virtual Connection over UDP
原文链接 原文:http://gafferongames.com/networking-for-game-programmers/virtual-connection-over-udp/ Introd ...
- 云虚拟主机开源 DedeCMS 安装指南
1. 获取主机 FTP 和 数据库 信息 1.1 FTP 信息 登录主机管理后台,在 站点信息 中获取到 FTP 和 数据库 的账号密码,连接地址. 如下图所示: 如果忘记密码,可以在这里进行 重置密 ...
- [NOIP2016]换教室 D1 T3 Floyed+期望DP
[NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...
- 【BZOJ】3309: DZY Loves Math
题意 \(T(T \le 10000)\)次询问,每次给出\(a, b(1 \le a, b \le 10^7)\),求 \[\sum_{i=1}^{a} \sum_{j=1}^{b} f((i, j ...
- 201301 JAVA题目0-1级
描述 编写一个函数,传入一个int型数组,返回该数组能否分成两组,使得两组中各元素加起来的和相等,并且,所有5的倍数必须在其中一个组中,所有3的倍数在另一个组中(不包括5的倍数),能满足以上条件,返回 ...
- 大端小端系统_union_栈的增长方向
一道题引发的思考: 1.看一下之前写的union的特点,理解一下共享内存的概念 2.栈的增长方向是从高地址向低地址增长(数组比较特别,a[0]在低地址,a[n-1]在高地址)(堆由低地址到高地址存储) ...
- jQuery系列:五个模块总结
Query插件,以备并希望在前端方面有所长进.请批评指正. 一,类型判断全解 JQuery判断类型扩展方法:$.type() /*type: function( obj ) { if ( obj == ...
- 手机端布局rem 与vm的使用
手机端原来的时候,在项目中使用js判断出html的字体,然后根据rem设置字体,但是js本着少用的原则,考虑用vm,vh等(顺带说一句,vm vh是网页可视区域宽度 高度 即浏览器宽度减去约16px) ...