PMD

PMD

An extensible cross-language static code analyzer.



Latest Version: 7.2.0 (31-May-2024)
Release Notes | Source


QuickStart


See also Getting Started
$ cd $HOME
$ wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.2.0/pmd-dist-7.2.0-bin.zip
$ unzip pmd-dist-7.2.0-bin.zip
$ alias pmd="$HOME/pmd-bin-7.2.0/bin/pmd"
$ pmd check -d /usr/src -R rulesets/java/quickstart.xml -f text
$ cd $HOME
$ curl -OL https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.2.0/pmd-dist-7.2.0-bin.zip
$ unzip pmd-dist-7.2.0-bin.zip
$ alias pmd="$HOME/pmd-bin-7.2.0/bin/pmd"
$ pmd check -d /usr/src -R rulesets/java/quickstart.xml -f text
  1. Download pmd-dist-7.2.0-bin.zip
  2. Extract the zip-archive, e.g. to C:\pmd-bin-7.2.0
  3. Add folder C:\pmd-bin-7.2.0\bin to PATH, either
    1. Permanently: Using System Properties dialog > Environment variables > Append to PATH variable
    2. Temporarily, at command line: SET PATH=C:\pmd-bin-7.2.0\bin;%PATH%
  4. Execute at command line: pmd.bat check -d c:\src -R rulesets/java/quickstart.xml -f text
  1. Install Chocolatey, if you don't already have it!
  2. Install package PMD: choco install -y pmd
  3. Run from the command-line! pmd check -d c:\src -R rulesets/java/quickstart.xml -f text
Checkout the existing rules for Java.


About PMD


PMD is an extensible multilanguage static code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It's mainly concerned with Java and Apex, but supports 16 other languages. It comes with 400+ built-in rules. It can be extended with custom rules. It uses JavaCC and Antlr to parse source files into abstract syntax trees (AST) and runs rules against them to find violations. Rules can be written in Java or using a XPath query.

Currently, PMD supports Java, JavaScript, Salesforce.com Apex and Visualforce, Kotlin, Swift, Modelica, PLSQL, Apache Velocity, JSP, WSDL, Maven POM, HTML, XML and XSL. Scala is supported, but there are currently no Scala rules available.

Additionally, it includes CPD, the copy-paste-detector. CPD finds duplicated code in Coco, C/C++, C#, Dart, Fortran, Gherkin, Go, Groovy, HTML, Java, JavaScript, JSP, Julia, Kotlin, Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex and Visualforce, Scala, Swift, T-SQL, Typescript, Apache Velocity, WSDL, XML and XSL.




Support


Need help?

Get Involved

See How to contribute to PMD and How to build PMD.

Our license: BSD-style.

Source Code: Check it out on github