--- title: PMD Making Rulesets short_title: Making Custom Rulesets tags: [customizing] summary: Making Custom Rulesets for PMD series: Customizing PMD weight: 4 last_updated: July 3, 2016 sidebar: mydoc_sidebar permalink: making_rulesets.html folder: mydoc --- {% include custom/series_customizing.html %} # How to make a new rule set Say you want to pick specific rules from various rule sets and customize them. You can do this by making your own rule set. ## Create a new ruleset.xml file Use one of the current rulesets as an example. Copy and paste it into your new file, delete all the old rules from it, and change the name and description. Like this: ```xml This ruleset checks my code for bad stuff ```` ## Add some rule references to it After you add these references it’ll look something like this: ```xml This ruleset checks my code for bad stuff 2 ``` >Notice that you can customize individual referenced rules. Everything but the class of the rule can be overridden in your custom ruleset. ## Excluding rules from a ruleset You can also make a custom ruleset that excludes rules, like this: ```xml Just the braces rules I like ``` ## Excluding files from a ruleset You can also exclude certain files from being processed by a ruleset using exclude patterns, with an optional overriding include pattern. A file will be excluded from processing when there is a matching exclude pattern, but no matching include pattern. Path separators in the source file path are normalized to be the ‘/’ character, so the same ruleset can be used on multiple platforms transparently. Additionally, this exclude/include technique works regardless of how PMD is used (e.g. command line, IDE, Ant), making it easier to keep application of your PMD rules consistent throughout your environment. Here is an example: ```xml My ruleset .*/some/package/.* .*/some/other/package/FunkyClassNamePrefix.* .*/some/package/ButNotThisClass.* ... ``` ## Reference it in your Ant task You can specify the full path to your custom ruleset name alongside of the built-in PMD rulesets - like this: ```xml ``` ## To see it in your IDE, add it to rulesets/rulesets.properties At least, that’s the way some of the IDE plugins do it. Some have other ways of adding custom rulesets. ## Send us feedback If you have suggestions on clarifying this document, please post them to [the forum](http://sourceforge.net/p/pmd/discussion/188192). Thanks! Finally, for many more details on building custom rulesets, pick up [PMD Applied](http://pmdapplied.com/)! {% include custom/series_customizing_previous.html %} {% include custom/series_customizing_next.html %} {% include links.html %}