genkins的报错排查

[ERROR] /root/.jenkins/workspace/car/src/main/java/com/zhengxin/tool/code/Code.java:[20,64] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[ERROR] /root/.jenkins/workspace/car/src/main/java/com/zhengxin/controller/WXController.java:[335,58] diamond

由于jenkins默认的jdk是1.5版本,所以编译war包的时候使用的1.5

也许有人问,我没有按装jdk1.5,安装的是1.8--------------------------------1.5是插件自带的

Maven默认用的是JDK1.5去编译

diamond运算符,指的是JDK1.7的一个新特性

List<String> list = new ArrayList<String>(); // 老版本写法
List<String> list = new ArrayList<>(); // JDK1.7及以后的写法
所以Maven默认使用JDK1.5去编译肯定是不认识这个东西的,针对这种问题,本文提供三种解决方案:

Ⅰ :在项目pom.xml中加入下面的配置即可

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Ⅱ:直接在pom.xml中配置Maven的编译插件也是可以的,像下面这样:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
 

Ⅲ:另外还有一种最终的解决方案,适用于idea下配置Maven的所有项目:

在配置的maven安装包的setting.xml中的profiles标签中加入以下标签

<profile>    
     <id>jdk-1.8</id>    
     <activation>    
        <activeByDefault>true</activeByDefault>    
        <jdk>1.8</jdk>    
     </activation>    
     <properties>    
        <maven.compiler.source>1.8</maven.compiler.source>    
        <maven.compiler.target>1.8</maven.compiler.target>    
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
     </properties>    
</profile>

这样之后就不会出现每次新创建的maven项目默认JDK版本都是1.5版本的了。
---------------------

原文:https://blog.csdn.net/xsm666/article/details/80076253

 
原文地址:https://www.cnblogs.com/zdqc/p/10287074.html