http://pmd.sourceforge.net/pmd-5.0.3/ant-task.html

在jenkins , ant , pmd进行集成的时候,build.xml模板如下,在网上找了一些模板,大部分都是A,B,C,D....狂copy,所以错的地方都一模一样

我这份已经自己试过,只要改下你们自己对应的目录即可。

<?xml version="1.0" encoding="UTF-8"?>

<project name="pmd" default="pmd">

<property environment="env"/>
<!-- 定义pmd的classpath,均为下载的pmd包解压后lib目录下的jar包-->
<path id="pmd.classpath">
<pathelement location="/var/lib/pmd-bin-5.4.2/lib/asm-5.0.4.jar"></pathelement>
<pathelement location="/var/lib/pmd-bin-5.4.2/lib/jaxen-1.1.6.jar"></pathelement>
<pathelement location="/var/lib/pmd-bin-5.4.2/lib/pmd-java-5.5.1.jar"></pathelement>
<pathelement location="/var/lib/pmd-bin-5.4.2/lib/"/>

<fileset dir="/var/lib/pmd-bin-5.4.2/lib/">
<include name="*.jar"> </include>
</fileset>
</path>

<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>
<target depends="pmd_html" name="pmd">
<!-- 定义代码检测规则,这里直接列出规则imports.xml和java-unusedcode规则,本例注释了,使用下面一种在另一文件中定义规则集-->
<!--
<pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode">
-->
<!-- 定义PMD检测规则所在的文件,规则集在pmdrule.xml文件中定义-->
<pmd rulesetfiles="rulesets/java/XXXrules.xml" encoding="UTF-8">
<!-- 输出XML格式的报告-->
<formatter type="html" tofile="pmd_report.html" toconsole="true"/>
<!-- 静态代码检测ExampleProject工程下src目录下的所有java文件-->
<fileset dir="${check_path}">
<include name="**/*.java">
</include></fileset>
</pmd>
</target>

<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>

<target name="pmd_html">
<!--
<pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode">
-->
<pmd rulesetfiles="rulesets/java/xxxxxkrules.xml" encoding="UTF-8">
<!-- 输出HTML格式的报告-->
<formatter type="xml" tofile="pmd_report.html" toconsole="true"/>
<fileset dir="${check_path}">
<include name="**/*.java">
</include></fileset>
</pmd>
</target>
</project>

05-10 20:20