Skip to main content
Version: 0.18.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

fetch_pmd

Example usage (generated):

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

fetch_pmd(
)

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.

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
report = 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

report

Required.

output file to generate

use_exit_code

Optional. Default: False

whether to fail the build when a lint violation is reported