Skip to main content
Version: 1.0.x

pmd

API for declaring a PMD lint aspect that visits java_library rules.

Typical usage:

First, call the fetch_pmd helper in WORKSPACE to download the zip file. Alternatively you could use whatever you prefer for managing Java dependencies, such as a Maven integration rule.

Next, declare a binary target for it, typically in tools/lint/BUILD.bazel:

java_binary(
name = "pmd",
main_class = "net.sourceforge.pmd.PMD",
runtime_deps = ["@net_sourceforge_pmd"],
)

Finally, declare an aspect for it, typically in tools/lint/linters.bzl:

load("@aspect_rules_lint//lint:pmd.bzl", "pmd_aspect")

pmd = pmd_aspect(
binary = "@@//tools/lint:pmd",
rulesets = ["@@//:pmd.xml"],
)

Macros and Functions

pmd_action

Run PMD as an action under Bazel.

Based on https://docs.pmd-code.org/latest/pmd_userdocs_installation.html#running-pmd-via-command-line

Example usage (generated):

load("@aspect_rules_lint//lint:pmd.bzl", "pmd_action")

pmd_action(
# Bazel Rule or Aspect evaluation context
ctx = None,
# label of the the PMD program
executable = None,
# java files to be linted
srcs = [],
# list of labels of the PMD ruleset files
rulesets = None,
# output file to generate
stdout = None,
)

ctx

Required.

Bazel Rule or Aspect evaluation context

executable

Required.

label of the the PMD program

srcs

Required.

java files to be linted

rulesets

Required.

list of labels of the PMD ruleset files

stdout

Required.

output file to generate

exit_code

Optional. Default: None

output file to write the exit code. If None, then fail the build when PMD exits non-zero.

options

Optional. Default: []

additional command-line options, see https://pmd.github.io/pmd/pmd_userdocs_cli_reference.html

lint_pmd_aspect

A factory function to create a linter aspect.

Attrs: binary: a PMD executable. Can be obtained from rules_java like so:

    ```
java_binary(
name = "pmd",
main_class = "net.sourceforge.pmd.PMD",
# Point to wherever you have the java_import rule defined, see our example
runtime_deps = ["@net_sourceforge_pmd"],
)
```

rulesets: the PMD ruleset XML files

Example usage (generated):

load("@aspect_rules_lint//lint:pmd.bzl", "lint_pmd_aspect")

lint_pmd_aspect(
binary = None,
rulesets = None,
)

binary

Required.

rulesets

Required.

rule_kinds

Optional. Default: ["java_binary", "java_library"]

fetch_pmd

Example usage (generated):

load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")

fetch_pmd(
)