Custom Java PMD rule: Can't find the class CustomRule

走远了吗. 提交于 2019-12-06 05:10:56

I've found a way: PMD will find your rule if you put it in a jar and place that jar in pmd-src-5.0.5\lib.

This is the shell command I use to make my rule accessible to PMD (my rules are in package mwe). Note that this is issued from my projects bin folder:

C:\Users\me\dev\CodeCheckerMWE\bin>jar -cf ..\pmd-src-5.0.5\lib\myrules.jar mwe

I have experimented with the classpath and the -auxclasspath option of PMD to make it accept different locations but with no success.

If anyone has a different (preferably more elegant) solution to this, please let me/us know.

By the way, for anyone else having problems, it looks like the instructions under http://pmd.sourceforge.net/snapshot/customizing/howtowritearule.html are outdated.

  • You need to add a description to the first child of the ruleset tag

    <description> Avoid using 'while' statements without using curly braces </description>

  • The syntax for actually running pmd seems to have changed, e.g.

./run.sh pmd -d /home/markus/project/src/de/ -f xml -R /home/markus/project/myrules.xml

  • You need to put the jar containing the java rule class under the lib folder of extracted binary zip of PMD. (See answer from Matthias Braun)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!