PMD has long been a great report to find out many useful details of your code base.
I find that the default ruleset does not contain some checks that I find very useful especially when I have more junior developers. I can catch many problematic errors.
<?xml version=”1.0″?>
<ruleset name="Custom ruleset" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description> This ruleset checks my code for bad stuff </description> <!-- Here's some rules we'll specify one at a time --> <rule ref="rulesets/basic.xml"/> <!-- We want to customize this rule a bit, change the message and raise the priority --> <rule ref="rulesets/basic.xml/EmptyCatchBlock" message="Must handle exceptions"> <priority>2</priority> </rule> <rule ref="rulesets/codesize.xml"/> <rule ref="rulesets/codesize.xml/CyclomaticComplexity"> <properties> <property name="reportLevel" value="5"/> </properties> </rule> <rule ref="rulesets/controversial.xml" /> <rule ref="rulesets/coupling.xml" /> <rule ref="rulesets/design.xml" /> <rule ref="rulesets/imports.xml" /> <rule ref="rulesets/logging-java.xml" /> <rule ref="rulesets/optimizations.xml" /> <rule ref="rulesets/strictexception.xml" /> <rule ref="rulesets/strings.xml" /> <rule ref="rulesets/sunsecure.xml" /> <rule ref="rulesets/typeresolution.xml" /> <rule ref="rulesets/unusedcode.xml" /> <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" /> <rule ref="rulesets/unusedcode.xml/UnusedPrivateField" /> <!-- Note we want everything from braces.xml except WhileLoopsMustUseBraces --> <rule ref="rulesets/braces.xml"> <exclude name="WhileLoopsMustUseBraces"/> </rule> </ruleset>
I uploaded my configuration to my server (http://www.baselogic.com/pmd-rules.xml), then I can access this on any project I am working on:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> <rulesets> <ruleset>http://www.baselogic.com/pmd-rules.xml</ruleset> </rulesets> <linkXref>true</linkXref> <targetJdk>${compiler.version}</targetJdk> </configuration> </plugin>
If you find you like your PMD a bit different, just customize the rules and put onto your webserver, then you can carry your rules with you.
Recent Comments