-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Build with annotation processor fails with higher tool Java language version #17281
Comments
I think the issue might be that the JDK version that's used to run JavaBuilder isn't controlled by Part of the motivation for that is that it lets us ensure JavaBuilder is running on a relative recent JDK version, even if a build wants to use an older Internally we're using the latest available JDK as the Another option here might just be to document how to configure a custom |
What I find surprising is that setting Is there a way to set up the toolchain so that a recent JDK is used for compilation (both target and tool) but target compilation outputs remain compatible with old JDKs and are also tested against these old JDKs? |
I remembered that this is eventually going to be improved by 75e0f7d making it into a The issue you encountered in this bug could still come up for
I agree this is having surprising results here, it's the result of all three of those being configured with
|
Thanks for the explanations. Does that mean that the language level of annotation processors is limited by the Java runtime used in the target configuration? If that's the case, would it help if processors were compiled for the target rather than the exec configuration? |
The language level of annotations processors is limited by the Ideally we'd want to ensure that the provided configurations satisfy the following constraints.
i.e. to build code at the Java N language level, you need a JavaBuilder running on JDK >= N to compile it, and a JDK >= N to execute it |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 30 days. It will be closed in the next 7 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". |
Possibly related: bazel-contrib/rules_jvm_external#895 |
One more note on that is that another way it satisfy the |
Work towards bazelbuild#17281 Closes bazelbuild#18344. PiperOrigin-RevId: 530662071 Change-Id: I9376cbc7117d9c8370cf50d42988cca44dad9785
Work towards #17281 Closes #18344. PiperOrigin-RevId: 530662071 Change-Id: I9376cbc7117d9c8370cf50d42988cca44dad9785 Co-authored-by: Fabian Meumertzheim <[email protected]> Co-authored-by: keertk <[email protected]>
Work towards bazelbuild#17281 Closes bazelbuild#18344. PiperOrigin-RevId: 530662071 Change-Id: I9376cbc7117d9c8370cf50d42988cca44dad9785
I also ran into this bug building bazel project on Mac. Can we bump the priority? |
When an annotation processor is built targeting a language level that isn't supported by the Java runtime used for compilation, JavaBuilder now throws an exception with actionable information. Example: ``` java.lang.IllegalStateException: The Java 17 runtime used to run javac is not recent enough to run the processor com.google.devtools.build.runfiles.AutoBazelRepositoryProcessor, which has been compiled targeting Java 20. Either register a Java toolchain with a newer java_runtime or, if this processor has been built with Bazel, specify a lower --tool_java_language_version. at com.google.devtools.build.buildjar.javac.BlazeJavaCompiler.initProcessAnnotations(BlazeJavaCompiler.java:119) ... ``` Work towards #17281 Closes #19548. PiperOrigin-RevId: 570766544 Change-Id: I71a53201a63f153b2318fff0a938a6626149e02f
When the Java system classpath extracted from the target Java runtime is more recent than the Java runtime used for Java compilation, JavaBuilder now emits a `[BazelJavaConfiguration]` diagnostic with actionable information instead of a bunch of "bad class file" errors on `module-info` files. Example: ``` error: [BazelJavaConfiguration] The Java 17 runtime used to run javac is not recent enough to compile for the Java 20 runtime in external/remotejdk20_linux. Either register a Java toolchain with a newer java_runtime or specify a lower --java_runtime_version. ``` Work towards #17281 Closes #19547. PiperOrigin-RevId: 571052686 Change-Id: Ifc1a2303895785482262db7653fe9eb8470361db
Warnings have been added in Bazel 7 or anything using a recent rules_java release. |
Description of the bug:
When a Java target uses a
java_plugin
that runs an annotation processor and the--tool_java_language_version
is higher than the--java_language_version
, the build fails even if--java_runtime_version
specifies a JDK version that is at least as high as--tool_java_language_version
.Given that this behavior is already triggered by depending on
@bazel_tools//tools/java/runfiles
, we experienced this as a regression when migrating to Bazel 6.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
With this WORKSPACE:
bazel build //:Main
passesbazel build //:Main --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17
fails withCaused by: java.lang.UnsupportedClassVersionError: com/google/devtools/build/runfiles/AutoBazelRepositoryProcessor has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
bazel build //:Main --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17 --java_runtime_version=remotejdk_17
fails with the same errorbazel build //:Main --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17 --java_runtime_version=remotejdk_17 --java_language_version=11
fails with the same errorbazel build //:Main --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17 --java_runtime_version=remotejdk_17 --java_language_version=17
passesI would argue that the failure in 2. is already unexpected: If the Java language levels in tools can't be higher than that for the target configuration, then what is the purpose of the flag? I always assumed that it exists to allow tooling to use modern Java features while limiting the rest of the codebase to something more compatible (e.g. Java 11).
The failures in 3. and 4. are definitely unexpected: Based on https://bazel.build/docs/bazel-and-java#hermetic-testing, I would have expected JDK 17 to be used for compilation with a
-target
value of 11 (3.) or 17 (4.). In both cases, the annotation processor compiled for a Java 17 runtime should be runnable. Instead, using--verbose_failures
, it looks likeremotejdk_11
is still used for compilation.Which operating system are you running Bazel on?
Linux
What is the output of
bazel info release
?6.0.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: