Add PMD rules into your project
pom.xml
<properties>
<pmd.failOnViolation>true</pmd.failOnViolation>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>pmd</id>
<phase>verify</phase>
<goals>
<goal>pmd</goal>
<goal>check</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<rulesets>
<ruleset>target/classes/tps_standard_pmd_ruleset.xml</ruleset>
</rulesets>
<format>xml</format>
<sourceEncoding>UTF-8</sourceEncoding>
<targetJdk>${java.version}</targetJdk>
<failOnViolation>${pmd.failOnViolation}</failOnViolation>
<failurePriority>3</failurePriority>
<excludes>
<exclude>**/*Bean.java</exclude>
<exclude>**/generated/*.java</exclude>
</excludes>
</configuration>
<inherited>true</inherited>
</plugin>
tps_standard_pmd_ruleset.xml
<?xml version="1.0"?>
<!-- ####################-->
<!-- Standard set of PMD rules to be applied & checked in all Pragthink projects -->
<!-- ####################-->
<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>
<rule ref="rulesets/java/strings.xml">
<exclude name="InefficientStringBuffering"/>
</rule>
<rule ref="rulesets/java/controversial.xml">
<exclude name="OnlyOneReturn"/>
<exclude name="AvoidFinalLocalVariable"/>
<exclude name="AtLeastOneConstructor"/>
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="UnusedModifier"/>
<exclude name="CallSuperInConstructor"/>
<exclude name="AssignmentInOperand"/>
<exclude name="UseConcurrentHashMap"/>
</rule>
<rule ref="rulesets/java/naming.xml">
<exclude name="LongVariable"/>
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="AbstractNaming"/>
</rule>
<rule ref="rulesets/java/logging-java.xml"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml">
<exclude name="ProperLogger"/>
</rule>
<rule ref="rulesets/java/sunsecure.xml">
<exclude name="ArrayIsStoredDirectly"/>
</rule>
<rule ref="rulesets/java/optimizations.xml">
<exclude name="SimplifyStartsWith"/>
<exclude name="AvoidInstantiatingObjectsInLoops"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="MethodArgumentCouldBeFinal"/>
</rule>
<rule ref="rulesets/java/junit.xml"/>
<rule ref="rulesets/java/design.xml">
<exclude name="ImmutableField"/>
<exclude name="AvoidDeeplyNestedIfStmts"/>
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
<exclude name="UncommentedEmptyConstructor"/>
<exclude name="UnnecessaryLocalBeforeReturn"/>
<exclude name="ConfusingTernary"/>
<exclude name="AvoidReassigningParameters"/>
<exclude name="SingularField"/>
</rule>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml">
<exclude name="AvoidThrowingNullPointerException"/>
</rule>
<rule ref="rulesets/java/javabeans.xml">
<exclude name="BeanMembersShouldSerialize"/>
</rule>
<rule ref="rulesets/java/clone.xml"/>
<rule ref="rulesets/java/finalizers.xml"/>
<rule ref="rulesets/java/imports.xml"/>
<rule ref="rulesets/java/coupling.xml">
<exclude name="ExcessiveImports"/>
<exclude name="LawOfDemeter"/>
</rule>
<rule ref="rulesets/java/codesize.xml">
<exclude name="TooManyMethods"/>
<exclude name="TooManyFields"/>
<exclude name="ExcessivePublicCount"/>
</rule>
<rule ref="rulesets/java/braces.xml"/>
<rule ref="rulesets/java/basic.xml">
<exclude name="CollapsibleIfStatements"/>
</rule>
<rule ref="rulesets/java/basic.xml/EmptyIfStmt">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml">
<exclude name="UnusedFormalParameter"/>
<exclude name="UnusedLocalVariable"/>
</rule>
</ruleset>
<properties>
<pmd.failOnViolation>true</pmd.failOnViolation>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>pmd</id>
<phase>verify</phase>
<goals>
<goal>pmd</goal>
<goal>check</goal>
<goal>cpd</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
<configuration>
<rulesets>
<ruleset>target/classes/tps_standard_pmd_ruleset.xml</ruleset>
</rulesets>
<format>xml</format>
<sourceEncoding>UTF-8</sourceEncoding>
<targetJdk>${java.version}</targetJdk>
<failOnViolation>${pmd.failOnViolation}</failOnViolation>
<failurePriority>3</failurePriority>
<excludes>
<exclude>**/*Bean.java</exclude>
<exclude>**/generated/*.java</exclude>
</excludes>
</configuration>
<inherited>true</inherited>
</plugin>
tps_standard_pmd_ruleset.xml
<?xml version="1.0"?>
<!-- ####################-->
<!-- Standard set of PMD rules to be applied & checked in all Pragthink projects -->
<!-- ####################-->
<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>
<rule ref="rulesets/java/strings.xml">
<exclude name="InefficientStringBuffering"/>
</rule>
<rule ref="rulesets/java/controversial.xml">
<exclude name="OnlyOneReturn"/>
<exclude name="AvoidFinalLocalVariable"/>
<exclude name="AtLeastOneConstructor"/>
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="UnusedModifier"/>
<exclude name="CallSuperInConstructor"/>
<exclude name="AssignmentInOperand"/>
<exclude name="UseConcurrentHashMap"/>
</rule>
<rule ref="rulesets/java/naming.xml">
<exclude name="LongVariable"/>
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="AbstractNaming"/>
</rule>
<rule ref="rulesets/java/logging-java.xml"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml">
<exclude name="ProperLogger"/>
</rule>
<rule ref="rulesets/java/sunsecure.xml">
<exclude name="ArrayIsStoredDirectly"/>
</rule>
<rule ref="rulesets/java/optimizations.xml">
<exclude name="SimplifyStartsWith"/>
<exclude name="AvoidInstantiatingObjectsInLoops"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="MethodArgumentCouldBeFinal"/>
</rule>
<rule ref="rulesets/java/junit.xml"/>
<rule ref="rulesets/java/design.xml">
<exclude name="ImmutableField"/>
<exclude name="AvoidDeeplyNestedIfStmts"/>
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
<exclude name="UncommentedEmptyConstructor"/>
<exclude name="UnnecessaryLocalBeforeReturn"/>
<exclude name="ConfusingTernary"/>
<exclude name="AvoidReassigningParameters"/>
<exclude name="SingularField"/>
</rule>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml">
<exclude name="AvoidThrowingNullPointerException"/>
</rule>
<rule ref="rulesets/java/javabeans.xml">
<exclude name="BeanMembersShouldSerialize"/>
</rule>
<rule ref="rulesets/java/clone.xml"/>
<rule ref="rulesets/java/finalizers.xml"/>
<rule ref="rulesets/java/imports.xml"/>
<rule ref="rulesets/java/coupling.xml">
<exclude name="ExcessiveImports"/>
<exclude name="LawOfDemeter"/>
</rule>
<rule ref="rulesets/java/codesize.xml">
<exclude name="TooManyMethods"/>
<exclude name="TooManyFields"/>
<exclude name="ExcessivePublicCount"/>
</rule>
<rule ref="rulesets/java/braces.xml"/>
<rule ref="rulesets/java/basic.xml">
<exclude name="CollapsibleIfStatements"/>
</rule>
<rule ref="rulesets/java/basic.xml/EmptyIfStmt">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml">
<exclude name="UnusedFormalParameter"/>
<exclude name="UnusedLocalVariable"/>
</rule>
</ruleset>
Comments
Post a Comment