[Java] Execute PMD Custom RuleSet using PMD command line #3053
-
Please, prefix the report title with the language it applies to within brackets, such as [java] or [apex]. If not specific to a language, you can use [core] Rule Set: Description:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other] |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @Neha-Dhonde ,
On the pmd documation page you can see a more exhaustive documentation about the various flags and possible output formats. But maybe you need help in putting your xpath expression developed with the Designer into a ruleset file? This part is indeed missing in the XPath Rule documentatio. <?xml version="1.0"?>
<ruleset name="Custom Rules"
xmlns="http://pmd.sourceforge.net/ruleset/3.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/3.0.0 http://pmd.sourceforge.net/ruleset_3_0_0.xsd">
<description>
Custom rules
</description>
<rule name="My Rule"
language="java"
message="violation message"
class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Rule Description
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
--- here comes your XPath expression
]]></value>
</property>
</properties>
<example>
<![CDATA[
public class ExampleCode {
public void foo() {
}
}
]]>
</example>
</rule>
</ruleset> Regards, |
Beta Was this translation helpful? Give feedback.
-
Thanks Andreas! Your inputs were of great help. I am able to run PMD through command line now. |
Beta Was this translation helpful? Give feedback.
-
@Neha-Dhonde glad you managed to work it out. |
Beta Was this translation helpful? Give feedback.
Hi @Neha-Dhonde ,
this should work with the following command line, given that your ruleset file is called "custom-rules.xml":
On the pmd documation page you can see a more exhaustive documentation about the various flags and possible output formats.
But maybe you need help in putting your xpath expression developed with the Designer into a ruleset file? This part is indeed missing in the XPath Rule documentatio.
Your ruleset "custom-rules.xml" could look like this: