Full reference for PMD's command-line interface, including options, output formats and supported languages
Edit me

Options

The tool comes with a rather extensive help text, simply running with -help!

Option Description Default value Applies to
-rulesets <refs>
-R <refs>
Required Comma-separated list of ruleset or rule references.
-dir <path>
-d <path>
Required Root directory for the analyzed sources.
-format <format>
-f <format>
Output format of the analysis report. The available formats are described here. text
-auxclasspath <cp> Specifies the classpath for libraries used by the source code. This is used to resolve types in source files. Alternatively, a file:// URL to a text file containing path elements on consecutive lines can be specified. Java
-benchmark
-b
Enables benchmark mode, which outputs a benchmark report upon completion. The report is sent to standard error.
-cache <filepath> Specify the location of the cache file for incremental analysis. This should be the full path to the file, including the desired file name (not just the parent directory). If the file doesn't exist, it will be created on the first run. The file will be overwritten on each run with the most up-to-date rule violations. This can greatly improve analysis performance and is highly recommended.
-debug
-verbose
-D
-V
Debug mode. Prints more log output.
-encoding <charset>
-e <charset>
Specifies the character set encoding of the source code files PMD is reading. The valid values are the standard character sets of java.nio.charset.Charset. UTF-8
-failOnViolation <bool>
--failOnViolation <bool>
Specifies whether PMD exits with non-zero status if violations are found. By default PMD exits with status 4 if violations are found. Disable this feature with -failOnViolation false to exit with 0 instead and just output the report. true
-filelist <filepath> Path to file containing a comma delimited list of files to analyze. If this is given, then you don't need to provide -dir.
-ignorelist <filepath> Path to file containing a comma delimited list of files to ignore. This option can be combined with -dir and -filelist. This ignore list takes precedence over any files in the filelist.
-help
-h
-H
Display help on usage.
-language <lang>
-l <lang>
Specify the language PMD should use. Used together with -version. See also Supported Languages.
-minimumpriority <num>
-min <num>
Rule priority threshold; rules with lower priority than configured here won't be used. 5
-norulesetcompatibility Disable automatic fixing of invalid rule references. Without the switch, PMD tries to automatically replace rule references that point to moved or renamed rules with the newer location if possible. Disabling it is not recommended.
-no-cache Explicitly disables incremental analysis. This switch turns off suggestions to use Incremental Analysis, and causes the -cache option to be discarded if it is provided.
-property <name>=<value>
-P <name>=<value>
Specifies a property for the report renderer. The option can be specified several times. []
-reportfile <path>
-r <path>
Path to a file in which the report output will be sent. By default the report is printed on standard output.
-shortnames Prints shortened filenames in the report.
-showsuppressed Causes the suppressed rule violations to be added to the report.
-stress
-S
Performs a stress test.
-suppressmarker <marker> Specifies the comment token that marks lines which PMD should ignore. NOPMD
-threads <num>
-t <num>
Sets the number of threads used by PMD. Set threads to 0 to disable multi-threading processing. 1
-uri <uri>
-u <uri>
Database URI for sources. If this is given, then you don't need to provide -dir. PLSQL
-version <version>
-v <version>
Specify the version of a language PMD should use. Used together with -language. See also Supported Languages.

Additional Java Runtime Options

PMD is executed via a Java runtime. In some cases, you might need to set additional runtime options, e.g. if you want to analyze a project, that uses one of OpenJDK’s Preview Language Features.

Just set the environment variable PMD_JAVA_OPTS before executing PMD, e.g.

export PMD_JAVA_OPTS="--enable-preview"
./run.sh pmd -d ../../../src/main/java/ -f text -R rulesets/java/quickstart.xml

Exit Status

Please note that if PMD detects any violations, it will exit with status 4 (since 5.3). This behavior has been introduced to ease PMD integration into scripts or hooks, such as SVN hooks.

0Everything is fine, no violations found
1Couldn't understand command-line parameters or PMD exited with an exception
4At least one violation has been detected, unless -failOnViolation false is set.

Supported Languages

The language is determined automatically by PMD from the file extensions. Some languages such as “Java” however support multiple versions. The default version will be used, which is usually the latest supported version. If you want to use an older version, so that e.g. rules, that suggest usage of language features, that are not available yet, won’t be executed, you need to specify a specific version via the -language and -version parameter.

These parameters are irrelevant for languages that don’t support different versions.

Example:

./run.sh pmd -d src/main/java -f text -R rulesets/java/quickstart.xml -language java -version 8
  • apex (Salesforce Apex)
  • java
    • Supported Versions: 1.3, 1.4, 1.5, 5, 1.6, 6, 1.7, 7, 1.8, 8, 9, 1.9, 10, 1.10, 11, 12, 13 (default), 13-preview
  • ecmascript (JavaScript)
  • jsp
  • modelica
  • plsql
  • scala
    • Supported Versions: 2.10, 2.11, 2.12, 2.13 (default)
  • vf (Salesforce VisualForce)
  • vm (Apache Velocity)
  • xml and xsl

Available Report Formats

PMD comes with many different renderers. The mnemonics in bold are used to select them on the command line, as arguments to the -format option. Some formats accept properties, which can be specified with the -property option on the command-line.

  • codeclimate: Renderer for Code Climate JSON format.

  • csv: Comma-separated values tabular format.

    Properties:

    • problem: Include problem column. Default: true.
    • package: Include package column. Default: true.
    • file: Include file column. Default: true.
    • priority: Include priority column. Default: true.
    • line: Include line column. Default: true.
    • desc: Include description column. Default: true.
    • ruleSet: Include Rule set column. Default: true.
    • rule: Include Rule column. Default: true.
  • emacs: GNU Emacs integration.

  • html: HTML format.

    Properties:

    • linePrefix: Prefix for line number anchor in the source file.
    • linkPrefix: Path to HTML source.
  • ideaj: IntelliJ IDEA integration.

    Properties:

    • classAndMethodName: Class and method name, pass .method when processing a directory.
    • sourcePath:
    • fileName:
  • summaryhtml: Summary HTML format.

    Properties:

    • linePrefix: Prefix for line number anchor in the source file.
    • linkPrefix: Path to HTML source.
  • text: Text format.

  • textcolor: Text format, with color support (requires ANSI console support, e.g. xterm, rxvt, etc.).

    Properties:

    • color: Enables colors with anything other than false or 0. Default: yes.
  • textpad: TextPad integration.

  • vbhtml: Vladimir Bossicard HTML format.

  • xml: XML format.

    Properties:

    • encoding: XML encoding format, defaults to UTF-8.
  • xslt: XML with a XSL transformation applied.

    Properties:

    • encoding: XML encoding format, defaults to UTF-8.
    • xsltFilename: The XSLT file name.
  • yahtml: Yet Another HTML format.

    Properties:

    • outputDir: Output directory.
Tags: userdocs