我有一个JAVA ANT项目,正在尝试将PMD脚本与其集成,以便可以检查项目中的所有错误和警告。
以下是我在build.xml中添加的ANT脚本的片段:

<property name="pmd.dir" value="buildconfig/build/pmd/" />
<path id="pmd.lib" >
   <fileset dir="${pmd.dir}">
     <include name="*.jar"/>
     <exclude name="/rulesets" />
   </fileset>
</path>
<target name="pmd" depends="init">
   <echo message="PMD Starting-----" />
   <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.lib"/>
   <pmd shortFilenames="true">
      <ruleset>unusedcode</ruleset>
      <formatter type="text" toFile="${pmd.dir}/pmd-ant-results.txt"/>
      <fileset dir="modules/app/">
         <include name="**/*.java"/>
      </fileset>
   </pmd>
</target>


ANT构建可以与PMD一起正常工作,并提供正确的错误报告,但是当PMD在代码中遇到任何错误时,我需要中止构建作为失败。
我尝试添加failOnRuleViolation="yes",但这并没有停止构建。
我还需要在脚本中添加其他内容吗?

最佳答案

尝试使用failOnRuleViolation="true"代替failOnRuleViolation="yes" ...

<pmd shortFilenames="true" failOnRuleViolation="true">
    ...


一些Ant任务将trueyes视为等效,但是许多任务根本不知道如何处理yes<pmd>可能是不处理yes的那些任务之一。

根据经验,将来始终使用truefalse而不是yesno避免这种麻烦。

关于java - 无法基于PMD错误/警告建立,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33209247/

10-11 22:54
查看更多