-
Notifications
You must be signed in to change notification settings - Fork 66
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
Java toolchain is not respected #148
Comments
To summarise some points from fmeum's reply on the Bazel issue and my follow-up comment:
It seems this also applies to the versions of We can use this to resolve the immediate issue by downgrading to |
Thought I would leave my comment here for the record: I believe the real fix is to add
And supply the toolchain_jdk for versions 8,9,10,11 (or at least a corresponding @bazel_tools//tools/jdk:remote_jdk{8,9,10}). This will not work out of the box without it because otherwise you will get
|
It seems that
--java_language_version
and related flags are not respected byrules_java
.Expected behaviour: setting the following flags in
.bazelrc
should build using a Java 17 JDK:Actual behaviour: the build happens with a Java 21 JDK.
Steps to reproduce: see https://github.com/swarren12/example-rules_java.
Specifically: include
rules_java
by way ofbzlmod
:Create a
java_library
with sources using Java 17 preview features:Set the properties above in
.bazelrc
. Attempt to build the code usingbazel build //:example
.The build will fail due to:
Adding the
build --javacopt="--enable-preview"
property to.bazelrc
and re-building causes the following error:We can see that the build is actually happening on
remotejdk21_linux
rather thanremotejdk17_linux
as would be expected.Why this is important: trying to convert a Gradle project to Bazel and prove correctness. The Gradle project builds on JDK 17 using
--enable-preview
. If we attempt to set--enable-preview
on here, the compiler complains that--enable-preview
can only be used with "release 21". Without setting--enable-preview
, preview features cannot be used and so the project cannot be migrated "like-for-like" without first being upgraded to Java 21.Running the build with
--toolchain_resolution_debug='@bazel_tools//tools/jdk:runtime_toolchain_type
shows the following:It seems from this that
remotejdk17_linux
is selected, but thenremotejdk21_linux
is picked in preference to it. I cannot see any obvious way of excludingremotejdk21_linux
from the selection process?Seems like a similar issue to #95. The solution here was to explicitly define JDKs, but that doesn't feel like the right solution?
The text was updated successfully, but these errors were encountered: