Search code examples
javatestingbazellombokannotation-processing

Lombok Annotations not processing in tests - Bazel


I am trying to use Lombok for a project along with Bazel. The Lombok annotations are not resolved in the test files. Does anyone have suggestions on how to resolve this issue?

I have enabled the Lombok Plugin and Annotation Processing in IntelliJ

java_library(
    name = "lombok",
    exports = [
        "@maven//:org_projectlombok_lombok",
    ],
    exported_plugins = [
        ":lombok_plugin"
    ],
)

java_plugin(
    name = "lombok_plugin",
    processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
    deps = [
        ":lombok_jar",
    ],
)

java_import(
    name = "lombok_jar",
    jars = [
      "@maven//:v1/https/repo1.maven.org/maven2/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar"
    ],
)

Thanks


Solution

  • You need to disable header compilation for lombok objects to work across targets - add the below snippet in .bazelrc

    # See https://github.com/bazelbuild/bazel/issues/12837.
    build --nojava_header_compilation
    test --nojava_header_compilation