我有一个 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 任务处理 true
和yes
等效,但许多任务不知道如何处理 yes
根本不。有可能<pmd>
是那些不处理 yes
的任务之一.
根据经验,请始终使用 true
来避免将来出现此问题。和false
而不是yes
和no
.
关于java - PMD 错误/警告导致构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33209247/