java - Pmd. how to configure ruleset? -
i have following pmd configuration in pom.xml
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-pmd-plugin</artifactid> <version>3.3</version> <configuration> <includetests>true</includetests> <printfailingerrors>true</printfailingerrors> <verbose>true</verbose> <rulesets> <ruleset>rulesets/java/basic.xml</ruleset> <ruleset>rulesets/java/braces.xml</ruleset> <!--<ruleset>rulesets/java/junit.xml</ruleset>--> <ruleset>rulesets/java/unusedcode.xml</ruleset> <!--<ruleset>rulesets/java/codesize.xml</ruleset>--> <ruleset>ruleset-naming.xml</ruleset> <ruleset>rulesets/java/imports.xml</ruleset> <ruleset>rulesets/java/empty.xml</ruleset> <ruleset>rulesets/jsp/basic.xml</ruleset> </rulesets> <includes> <include>**\/*.jsp</include> <include>**\/*.java</include> </includes> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> <configuration> <excludefromfailurefile>${basedir}/src/main/resources/exclude-pmd.properties</excludefromfailurefile> </configuration> </execution> </executions> </plugin>
if uncomment
<ruleset>rulesets/java/junit.xml</ruleset>
pmd complains:
junit assertions should include message. unittestcontainstoomanyasserts priority:3 junit tests should not contain more 1 assert(s) junitassertionsshouldincludemessage priority:3 junit assertions should include message.
i don't want follow these rules. want disable them. not find these files in project.
where can show rule set? how can disable concrete rule?
p.s.
it content of ruleset-naming.xml
<ruleset name="maven 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"> <rule ref="rulesets/java/naming.xml"> <exclude name="shortvariable"/> <exclude name="longvariable"/> <exclude name="shortclassname"/> </rule> <rule ref="rulesets/java/junit.xml"> <exclude name="junitassertionsshouldincludemessage"/> </rule> </ruleset>
but run build , anyway see message:
[info] pmd failure: com.terminal.service.impl.contentserviceimpltest:111 rule:junitassertionsshouldincludemessage priority:3 junit assertions should include message.
solution:
- remove
<ruleset>rulesets/java/junit.xml</ruleset>
pom.xml - added inside
ruleset-naming.xml
http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:nonamespaceschemalocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/java/junit.xml"> <exclude name="junitassertionsshouldincludemessage"/> <exclude name="junittestcontainstoomanyasserts"/> <exclude name="junittestsshouldincludeassert"/> </rule>
unforunately cannot format content correctly.
picture:
it possible exclude pmd checks per class , per rule. configured excludefromfailurefile
attribute of maven-pmd-plugin
. attribute must point properties file lists excludes.
org.apache.maven.classa=unittestcontainstoomanyasserts,junitassertionsshouldincludemessage org.apache.maven.classb=unittestcontainstoomanyasserts,junitassertionsshouldincludemessage
if have lot of classes , want disable checks every class, option copy file rulesets/java/junit.xml
, make own rule set deleting rules not want check (see answer).
Comments
Post a Comment