jenkins 配置checkstyle

首先,我们先在jenkins上新建一个item:

[img]http://dl2.iteye.com/upload/attachment/0110/9390/02d25777-20df-3971-9215-4de644085829.png[/img]

然后,就给项目命名和选择项目类型:

[img]http://dl2.iteye.com/upload/attachment/0110/9392/5b485454-edbf-30c5-af60-457e9748b81c.png[/img]

点击[OK]之后,就到了如下页面:

[img]http://dl2.iteye.com/upload/attachment/0110/9400/04987384-75a5-339a-9fee-6c2c157100d9.png[/img]

[img]http://dl2.iteye.com/upload/attachment/0110/9402/74cb23de-12bd-3733-866f-fc00a2bd8ada.png[/img]


[img]http://dl2.iteye.com/upload/attachment/0110/9404/2288db05-4d04-3258-8786-f7cf6c9a2db8.png[/img]

save完之后,项目就新建好了。

接下来讲讲配置checkstyle,要支持checkstyle就要在pom文件里添加checkstyle的支持。
先看一下pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>css</groupId>
<artifactId>hw</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>hw</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
<configuration>
<consoleOutput>false</consoleOutput>
<outputFileFormat>xml</outputFileFormat>
<configLocation>fcm-cs-check.xml</configLocation>
<linkXRef>false</linkXRef>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.9</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>


这样子就可以支持mvn checkstyle:checkstyle命令了

指定checkstyle 文件的位置有两种方式。
第一种就是刚刚在上面的pom.xml中提到的。
<configLocation>fcm-cs-check.xml</configLocation>


必须把文件的配置放在<build>元素里面。参考阅读:[url]http://stackoverflow.com/questions/8975096/maven-checkstyle-configlocation-ignored[/url]
并且fcm-cs-check.xml 必须要跟pom.xml是同一层目录的。
如下图:

[img]http://dl2.iteye.com/upload/attachment/0110/9410/5c7354e0-48b4-3678-be70-4dfc4329bc19.png[/img]

这样子就可以report出checkstyle了。

第二种方法是:
在mvn 命令中指定checkstyle.config.location,参考:[url]https://dustplanet.de/howto-use-your-own-checkstyle-rules-in-your-jenkinsmaven-job/[/url]

两种方式只要支持一种就可以了。


贴最后一张成果图:

[img]http://dl2.iteye.com/upload/attachment/0110/9418/13156eb5-06f2-3f7b-acb0-89dd7214be90.png[/img]

--EOF--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值