Skip to content


GitHub stars sarif GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

pmd documentation

pmd - GitHub

Configuration in MegaLinter

Variable Description Default value
JAVA_PMD_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
JAVA_PMD_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
JAVA_PMD_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
JAVA_PMD_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
JAVA_PMD_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
JAVA_PMD_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
JAVA_PMD_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
JAVA_PMD_PRE_COMMANDS List of bash commands to run before the linter None
JAVA_PMD_POST_COMMANDS List of bash commands to run after the linter None
JAVA_PMD_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling JAVA_PMD and its pre/post commands None
JAVA_PMD_CONFIG_FILE pmd configuration file nameUse LINTER_DEFAULT to let the linter find it java-pmd-ruleset.xml
JAVA_PMD_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
JAVA_PMD_DISABLE_ERRORS Run linter but consider errors as warnings false
JAVA_PMD_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
JAVA_PMD_CLI_EXECUTABLE Override CLI executable ['/usr/bin/pmd/bin/pmd']

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 124 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 83 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 53 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .java

How the linting is performed

  • pmd is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

pmd --rulesets java-pmd-ruleset.xml --dir
pmd --rulesets java-pmd-ruleset.xml --file-list /tmp/list-off-files-generated-by-megalinter.txt
pmd --rulesets java-pmd-ruleset.xml --dir /path/to/sources

Help content

Usage: pmd [-hV] [COMMAND]
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
  check                The PMD standard source code analyzer
  cpd                  Copy/Paste Detector - find duplicate code
  designer             The PMD visual rule designer
  cpd-gui              GUI for the Copy/Paste Detector
                         Warning: May not support the full CPD feature set
  ast-dump             Dumps the AST of parsing source code
  generate-completion  Generate bash/zsh completion script for pmd.
Exit Codes:
  0   Successful analysis, no violations found
  1   An unexpected error occurred during execution
  2   Usage error, please refer to the command help
  4   Successful analysis, at least 1 violation found

Installation on mega-linter Docker image

  • Dockerfile commands :
# Parent descriptor install
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk
# Linter install
RUN wget --quiet${PMD_VERSION}/pmd-dist-${PMD_VERSION} && \
    unzip pmd-dist-${PMD_VERSION} || echo "Error unzipping" && \
    rm pmd-dist-${PMD_VERSION} || echo "Error rm" && \
    mv pmd-bin-${PMD_VERSION} /usr/bin/pmd || echo "Error mv" && \
    chmod +x /usr/bin/pmd/bin/pmd || echo "Error chmod"