Plugin checks

Error Prone supports custom checks via a plugin mechanism. Plugin checks are loaded dynamically from the annotation processor path using java.util.ServiceLoader.

Using AutoService to specify the service descriptor is recommended.


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
  name = "MyCustomCheck",
  // ...
public class MyCustomCheck extends BugChecker implements MethodInvocationTreeMatcher {
  public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    // TODO:

Build system support

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


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

    name = "MyCustomCheckPlugin",
    srcs = [""],
    deps = [


Starting in version 3.5, maven-compiler-plugin allows the processor path to be configured with the annotationProcessorPaths parameter.


Starting in version 4.6, Gradle provides support for configuring the processor path:

dependencies {
  annotationProcessor project(':custom-checks')

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.