About
Side Projects
Blog
2026-05-01

Bazel and Java Annotation Processors

I’ve recently been experimenting with a Java library which, in order to function, requires that Java annotation processors be used. I wanted to see how this would work with Bazel. It turns out not too difficult when you know how.

Make sure the Maven dependency for the annotation is declared in your Bazel Module’s definition;

maven.install(
    artifacts = [
        ...
        "io.avaje:avaje-inject-generator:%s" % AVAJE_HTTP_INJECT_GENERATOR,
        ...

Declare the annotation processor using the java_plugin rule in your BUILD.bazel file;

java_plugin(
    name = "avaje_inject_generator",
    processor_class = "io.avaje.inject.generator.InjectProcessor",
    deps = [
        "@maven//:io_avaje_avaje_inject_generator",
    ],
)

Now in your java_library or java_binary you can specify the use of the generator using the plugins attribute;

java_binary(
    name = "my_thing",
    ...
    plugins = [
        ":avaje_inject_generator",
    ],
    ...
)

This sees to work well.