Example

Plugin checks are implemented exactly the same way as the built-in checks,
except for the @AutoService(BugChecker.class) annotation:

@AutoService(BugChecker.class)// the service descriptor@BugPattern(name="MyCustomCheck",// ...)publicclassMyCustomCheckextendsBugCheckerimplementsMethodInvocationTreeMatcher{@OverridepublicDescriptionmatchMethodInvocation(MethodInvocationTreetree,VisitorStatestate){// TODO:}}

Build system support

Plugin checks should work with any build system that allows setting the
annotation processor classpath.

Bazel

Bazel allows annotation processors to be configured using the
java_plugin rule:

Command-Line Arguments

Plugin checkers can accept additional configuration flags by defining
a single-argument constructor taking an ErrorProneFlags object (see
the flags docs). However, note
that plugin checkers must also define a zero-argument constructor, as
they are loaded by a ServiceLoader. The actual checker instance
used by Error Prone will be constructed using the ErrorProneFlags
constructor.