在用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 表达式的更多相关文章

  1. maven编译报错 -source 1.5 中不支持 lambda 表达式(转)

    原文链接:http://blog.csdn.net/kai161/article/details/50379418 在用maven编译项目是由于项目中用了jdk 1.8, 编译是报错  -source ...

  2. maven编译报错 -source 1.7 中不支持 lambda 表达式

    Maven项目编译失败: [ERROR] COMPILATION ERROR : [INFO] ---------------------------------------------------- ...

  3. 【Maven】Maven-maven编译报错 -source 1.5 中不支持 lambda 表达式

    Maven-maven编译报错 -source 1.5 中不支持 lambda 表达式 maven lambda_百度搜索 maven编译报错 -source 1.5 中不支持 lambda 表达式 ...

  4. maven编译报错 -source 1.5 中不支持 lambda(或diamond) 表达式,编码 UTF-8 的不可映射字符

    在用maven编译项目是由于项目中用了jdk 1.8, 编译是报错  -source 1.5 中不支持 lambda 表达式. 错误原因: Maven Compiler 插件默认会加 -source ...

  5. IDEA无法编译java8的lambda表达式提示Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式

    在idea中新建了一个java8的项目,但是写lambda表达式提示语法错误,提示如下错误信息: Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式 (请 ...

  6. IDEA中打包Spark项目提示Error:(16, 48) java: -source 1.5 中不支持 lambda 表达式

    在idea中新建了一Spark的项目,在做项目的编译打包的时候,提示如下错误信息: Error:(, ) java: -source 1.5 中不支持 lambda 表达式 (请使用 -source ...

  7. maven 报错 -source 1.5 中不支持 diamond 运算符

    maven 执行install 报-source 1.5 中不支持 diamond 运算符 解决办法, 指定编译版本 <build> <plugins> <plugin& ...

  8. maven编译报错 错误: -source 1.5 中不支持 lambda 表达式

    ji与基于maven的工程java应用程序非web应用的 参考这个https://www.cnblogs.com/softidea/p/6256543.html 但是java应用里边是没有这个配置的, ...

  9. 解决maven打jar包报错 source 1.3 中不支持

    问题:maven在进行打包时,报 '请使用-source 5 或者更高版本以启用XX'的信息并导致打包失败. 原因:maven默认的编译插件的java版本较低,导致其不支持例如泛型,注解等用法. 解决 ...

随机推荐

  1. php实现数据库数据读取生成缓存文件

    有些时候我们希望减少对数据库的 查询来提高程序的性能,因为这些数据不是经常变更的,而是会在很长一段时间内都不会变化,因此,我们每连接一次数据库,都会把相应的结果用文件的形式保存 起来.比如对于一个商城 ...

  2. 首师大附中互测题:99999999海岛帝国后传:算法大会【D001】

    [D001]99999999海岛帝国后传:算法大会[难度:D] ———————————————————————————————————————————————————————————————————— ...

  3. js最佳继承范型

    先回想下怎么给一个类设置属性:1.构造函数 内  通过this2.prototype中的属性两者的区别就是构造函数中的属性是每个实例私有的,而prototype中的属性是所有实例共有的(一般方法和静态 ...

  4. vs发布的程序不依赖运行时库msvcp100.dll

      [摘要:msvcr100.dll:MS Visual C Runtime 100 msvcp100.dll:MS Visual CPp 100 vs建立的工程,运转时库的范例有MD(MDd)战MT ...

  5. 【原】iOS学习之苹果开发者账号的相关操作

    1.苹果开发者账号分类 按价格分类 免费 ① 个人申请账号 仅可以用于真机调试 ② 院校账号 仅可以用于真机调试 通过苹果认证的高校可以使用 99$ ① 个人账号 ② 企业(公司)账号 申请所需的条件 ...

  6. 【原】iOS学习之UIStoryboardSegue解析

    在 Storyboard 的可视化编程中,跳转界面就是按住 Ctrl 使用鼠标头一条连线就可以解决,相当的简单!本篇博客主要就是介绍这条连线,在iOS中,这条连线也是一个对象,也有其自己的初始化方法和 ...

  7. android 修改 SwitchPreferenceCompat 高度,内边距,字体大小

    public class FontSizeSwitchPreferenceCompat extends SwitchPreferenceCompat { private Context mContex ...

  8. YACC和BISON学习心得

    最近学习了YACC和BISON两个工具,参考书籍<YACC和BISON>,通过里面的例子,明白了如何编写自己的解释性语言.

  9. c#操作mysql积累

    1,连接字符串 Server=localhost;port=;User ID=root;password=admin;database=;charset=utf8;Allow User Variabl ...

  10. 01@MySQL_Course_LabVIEW+MySQL程序开发

    LabVIEW+MySQL程序开发 大数据时代,LabVIEW程序开发怎么能少了数据库这一强大的工具,然而大多数的LabVIEW工程师对于数据库的概念了解比较少,所以本课程重点介绍如何利用MySQL, ...