bazel: Bazel project with Lombok fails to build on Bazel 4.0.0 rc10
Description of the problem / feature request:
I have a java project that uses Project Lombok. Currently it is building with bazel v3.7.2 but when I try to upgrade to bazel v4.0.0rc10, the build errors out because it cannot find symbols that are being generated by lombok.
Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
git clone https://github.com/bradsherman/examples.git
cd examples/java-tutorial
git checkout lombok-bazel
wget https://github.com/bazelbuild/bazel/releases/download/3.7.2/bazel-3.7.2-installer-linux-x86_64.sh
chmod +x bazel-3.7.2-installer-linux-x86_64.sh
./bazel-3.7.2-installer-linux-x86_64.sh --user
~/bin/bazel run //:ProjectRunner
# builds, prints out "Hi!", then "Test"
wget https://releases.bazel.build/4.0.0/rc10/bazel-4.0.0rc10-installer-linux-x86_64.sh
chmod +x bazel-4.0.0rc10-installer-linux-x86_64.sh
./bazel-4.0.0rc10-installer-linux-x86_64.sh --user
~/bin/bazel run //:ProjectRunner
# build error out "cannot find symbol"
What operating system are you running Bazel on?
Ubuntu 18.04
What’s the output of bazel info release?
release 4.0.0rc10
What’s the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
https://github.com/bradsherman/examples.git 4183fc709c26a00366665e2d60d70521dc0b405d 22236db1d29e75a8165a94f5dc9cb10ff890480c
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (10 by maintainers)
Would it be possible to add an attribute or tag or similar to disable turbine for individual targets, rather than at a whole-build level? It’d be nice to get most of the speed-up, and only fall back to ijar where it’s really necessary.
I tried the patch proposed with Bazel 6.0.0 and JVM external rules version 4.5 and got this error:
I managed to work around that in the following way:
I’m also new to Bazel. But I think the original commenter already had Lombok set up as a plugin. So the
--nojava_header_compilationworkaround is only necessary, as was previously pointed out, if the Lombok generated code is used in a different library/binary than the target using lombok. But for completeness, I think the following is the plugin set up you want:The 2 differences from what was posted earlier are the
generates_apiflag and not needing thejava_importWe’ve created some rules that do delombok: https://github.com/bookingcom/rules_lombok_java_library
And we have a sample project that shows usage as well based on the examples shared on this thread
I’m going to close this out, because it isn’t a bug in Bazel. The Lombok annotation processor depends on unsupported compiler internals to work with javac and ecj, and doesn’t work with other implementations of the annotation processing API.
Other annotation processors that generate code for value classes, like AutoValue, are fully supported by Bazel. For code using Java 14+, records are also a good option.
For projects that needs to use Lombok with Bazel, I recommend using https://projectlombok.org/features/delombok instead of relying on the annotation processor.
As it took me quite some time to figure out a good workaround (the mentioned ones didn’t work) as a Bazel newcomer, here is how I got it working.
Assuming a installed version of
1.18.20for lombok via maven_install, add the following to yourBUILDfile::lombokcan now be used as a dep for yourjava_library:I agree having an attribute to configure this for individual targets might be nice, I’ll defer to @comius on the priority of that for Bazel.
I can also think of a few alternatives that work today:
--java_header_compilationon particular targets (or in general to set native Bazel flags) using configuration transitions, e.g. for the example in https://github.com/bazelbuild/bazel/issues/12837#issue-787143314:Thank you for the explanation and the workaround. Passing
--nojava_header_compilationworked for me!