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.
Plugin checks are implemented exactly the same way as the built-in checks,
except for the @AutoService(BugChecker.class) annotation:
Plugin checks should work with any build system that allows setting the annotation processor classpath.
java_library(
name = "demo",
srcs = ["java/com/example/Demo.java"],
plugins = [":my_custom_check"],
)
java_plugin(
name = "my_custom_check",
srcs = ["java/com/example/MyCustomCheck.java"],
deps = [
":auto_service",
"@maven//:com_google_errorprone_error_prone_annotation",
"@maven//:com_google_errorprone_error_prone_check_api",
],
)
java_library(
name = "auto_service",
exported_plugins = [
":auto_service_plugin",
],
exports = [
"@maven//:com_google_auto_service_auto_service_annotations",
],
)
java_plugin(
name = "auto_service_plugin",
processor_class = "com.google.auto.service.processor.AutoServiceProcessor",
deps = [
"@maven//:com_google_auto_service_auto_service",
],
)
Starting in version 3.5, maven-compiler-plugin allows the processor path to be configured with the annotationProcessorPaths parameter.
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.