How to pass lombok.config to java_library

256 views
Skip to first unread message

Christopher Kilian

unread,
Apr 7, 2022, 6:35:09 PM4/7/22
to bazel-discuss
Hello!

We're using lombok in our Bazel package and we have a couple of lombok.config files that we want to get picked up and processed while creating a java_library. In other build systems that we've used, you could pass this file as part of the srcs, but Bazel does not allow any files that do not end in .java, .srcjar, or .properties to be passed through the srcs. I tried adding the lombok.config file to resources, but the plugin did not add the extra annotations that were specified in the lombok.config file, so I don't think it was processed. What is the correct way to have the lombok plugin respect the lombok.config file?

Thanks!

Chris

Christopher Kilian

unread,
Apr 13, 2022, 9:53:38 PM4/13/22
to bazel-discuss
Seems I was mistaken here, the lombok.config file is successfully being moved to the execroot and lombok is finding it. Lombok is successfully finding the lombok.addLombokGeneratedAnnotation key in the config file and in the debugger it seems that lombok is adding the @Generated annotation to the generated code. However, when I decompile the jar, the annotation is not present. The annotation processors are definitely running, because the Builders are being generated. However, the generated code does not seem to have any of the annotations that lombok is supposedly adding. Does anyone know why this might be?

Christopher Kilian

unread,
Apr 14, 2022, 5:31:17 PM4/14/22
to bazel-discuss
Created a minimal example to demonstrate the problem: https://github.com/ckilian867/bazel-lombok-generated-annotation

A jar generated by Buck has the annotations, but the jar generated by Bazel does not (I tried Bazel 4.2.2, Bazel 5.0.0, and Bazel 5.1.0). In the debugger, it seems that Lombok is adding the annotation, but for some reason it isn't ending up in the final jar.

Christopher Kilian

unread,
Apr 25, 2022, 7:10:34 PM4/25/22
to bazel-discuss
For future reference:

You can get it picked up by creating a custom java_toolchain and putting the file in java_toolchain.javabuilder_data. See more details here: https://github.com/bazelbuild/bazel/issues/15314
Reply all
Reply to author
Forward
0 new messages