New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bazel project with Lombok fails to build on Bazel 4.0.0 rc10 #12837
Comments
cc @comius I can reproduce:
The lombok processor logs the following warning when running as part of the action that generates
Since lombok doesn't run, the symbols it generates (like This is the result of 10ffddb, because lombok relies on javac internals and doesn't support the non-javac-based turbine implementation. It's possible to work around this by disabling the 'header compilation' feature by passing |
Thank you for the explanation and the workaround. Passing |
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 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:
def _java_header_compilation_transition(settings, attr):
_ignore = (settings, attr)
return {"//command_line_option:java_header_compilation": "False"}
java_header_compilation_transition = transition(
implementation = _java_header_compilation_transition,
inputs = [],
outputs = ["//command_line_option:java_header_compilation"],
)
def _java_library_without_header_compilation(ctx):
return [java_common.merge([d[JavaInfo] for d in ctx.attr.dep])]
java_library_without_header_compilation = rule(
implementation = _java_library_without_header_compilation,
attrs = {
"dep": attr.label(
providers = [JavaInfo],
mandatory = True,
cfg = java_header_compilation_transition,
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
)
|
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
|
@hobofan that example isn't affected. The issue is that the API generated by lombok for If you have an example like:
Where |
Hmm strange. I was only trying to use the methods generated by lombok from inside the same library and this was the only way I was able to get it to work. I don't know if the underlying cause is the same, but at least from a users perspective it looked the same as the reported issues, so maybe someone else with the same problem as me will stumble upon it and find it helpful 🤷 |
What else did you try that didn't work? Is the report more that |
IIRC I tried these things in roughly that order:
And then I finally found that workaround, or rather "verbose correct way". I think bazelbuild/rules_jvm_external#144 is probably the right way to handle it and what I was missing, but all web searches for Bazel + lombok led me here with seemingly fitting error messages. |
We'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 also new to Bazel. But I think the original commenter already had Lombok set up as a plugin. So the
The 2 differences from what was posted earlier are the |
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:
|
Thanks a lot for the workaround for disabling However, I noticed one issue: when creating This can be of course workaround using virtual java_plugin(
name = "lombok_plugin",
generates_api = True,
processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
visibility = ["//visibility:public"],
deps = ["@lombok//jar"],
)
java_library(
name = "lombok",
exported_plugins = [":lombok_plugin"],
visibility = ["//visibility:public"],
exports = ["@lombok//jar"],
)
java_binary(
name = "lombok-deploy-env",
main_class = "Dummy",
visibility = ["//visibility:public"],
runtime_deps = [
":lombok",
],
) So that now t would work as expected and not leaking the java_binary(
name = "github-oauth",
deploy_env = ["//plugins/github:lombok-deploy-env"],
main_class = "Dummy",
runtime_deps = [":github-oauth-lib"],
)
java_library_without_header_compilation(
name = "github-oauth-lib",
dep = ":github-oauth-lib-impl",
visibility = ["//visibility:public"],
)
java_library(
name = "github-oauth-lib-impl",
srcs = glob(["src/main/java/**/*.java"]),
deps = PLUGIN_DEPS_NEVERLINK,
) Why this complication is happening in the first place, and is there any simpler workarounds? |
@davido it looks like your example has a |
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. |
You are totally right, it's unrelated to My impression was, that Thanks for mentioning it's a much simpler workaround is to use java_library(
name = "lombok",
exported_plugins = [":lombok_plugin"],
visibility = ["//visibility:public"],
neverlink = True,
exports = ["@lombok//jar"],
) [1] https://gerrit-review.googlesource.com/c/gerrit/+/352391 |
Lombok is a useful library helper, but has a number of disadvantages: 1. It introduces third party dependency, and upgrade to new Java versions might be delayed by the lombok support of new language releases. 2. It complicates IDEs integration. Separate plugins might be required to support diferent IDEs. 3. Given that this is not a standard annotation processor it complicates build integrations. See this issue for problems with Bazel integration: [1]. [1] bazelbuild/bazel#12837 Change-Id: I538ee31a4e7b5237aa8160d8b6d552a28f6d6e74
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.
What operating system are you running Bazel on?
What's the output of
bazel info release
?What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?The text was updated successfully, but these errors were encountered: