I am trying to figure where is the default ruleset file, name of the default ruleset file and how do we add our own rules to it. I tried to google, but that is just confusing me. So far, I have put the pmd plugin inside eclipse plugins folder and in preferences I can see PMD.
- 
                    4I think you should accept the answer. It is correct and helpful – kostja Aug 14 '11 at 19:15
- 
                    If you use maven integrate pmd with the maven using the "maven-pmd-plugin". Configure rules in the pom.xml – Christophe Roussy Apr 24 '18 at 08:20
2 Answers
The standard ruleset file is *.xml inside pmd-bin-x.x.x.zip/.../lib/pmd-x.x.x.jar/rulesets/, refer to http://pmd.sourceforge.net/rules/index.html.
For example for pmd 7.0 rc 3 under windows the jar files with rulesets look like this
The default ruleset file of PMD Eclipse Plugin is inside pmd___.jar in your {IDE}/plugins/..., but you should not make any changes in that file. Add/edit the rules in Eclipse Preferences, any changes will take precedence over the default ruleset.
Given that pmd was unpacked under windows at C:\Apps\pmd-bin-7.0.0-rc3 the folder with jar files looks like this
You can unpack a jar file to see the files inside:
 
    
    - 5,527
- 7
- 48
- 77
 
    
    - 6,745
- 2
- 38
- 52
- 
                    Also helpful is the [PMD - IDE Integrations page](http://pmd.sourceforge.net/pmd-4.3.0/integrations.html#Eclipse). – Pixelstix Aug 15 '17 at 13:58
After messing with Ant and PMD for a good long while, this is the complete solution I have come up with. Modify to your own taste.
This sets the initial directories I use.
<property name="doc" location="doc" />               <!-- Root for all documentation: -->
<property name="pmddoc" location="${doc}/pmddoc" />  <!-- PMD results -->
This is my task definition, which points to the latest version of PMD at this time where I have it stored. It includes the PMD Jar itself (where all the rules are stored) and all PMD's dependencies as well.
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
    <classpath>
        <fileset dir="C:\development\pmd-bin-5.0-alpha">
            <include name="lib/*.jar"/>    <!-- also includes pmd's file, which has all the rulesets I need. -->
        </fileset>
    </classpath>
</taskdef>
In initialization, I create the documentation folder if needed:
<target name="init">
    <mkdir dir="${pmddoc}" />
</target>
...And finally, I created a target specifically for creating a PMD report in HTML form. Here it is.
<target name="pmd" depends="init">
    <pmd>
        <formatter type="html" toFile="${pmddoc}/pmd_src_report.html" toConsole="true"/>
        <ruleset>rulesets/java/basic.xml</ruleset> <!-- references file in PMD's .jar -->
        <!-- Files PMD will test. -->       
        <fileset dir="${src}">
            <include name="**/*.java"/>     <!-- required to avoid firing off .aj errors. This ruleset doesn't support AspectJ. -->
        </fileset>
    </pmd>
</target>
 
    
    - 5,607
- 3
- 39
- 65
 
     
    
