-
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
--release javacopt does not link against specified version #6652
Comments
The recommended way to target Java 7 is by setting The platform APIs that the compilation uses are chosen based on |
Is there an ETA when My actual requirement is a bit more involved than with the mentioned example. I ultimately need to be able to link different projects against different Java releases. The proposed Ideally, |
What happens if e.g. you have a If it's okay to do built the two Java binaries that require different Java releases within different Bazel invocations, you can always have different |
If a This might be something we could model with constraints and I've thought about doing something like that for the existing
To clarify, that's not a blocker for supprting it in Bazel, it's just that we might have more motivation to add the support if Bazel itself was able to use the flag. As it is we have no choice to continue supporting |
I have it working with Bazel 0.12 by the means of a custom @lberki Not sure using multiple Bazel invocations could work. The Java 8 + 9 projects might have Java 7 project dependences, but invocation with a different Anyway, thanks much for your help and keep up the good work! I hope Java 9 support will get better over time. |
Hi. I've been trying to set up Bazel (5.0.0) to use JDK 17 for compilation and execution, but to generate code for Java 11.
so the flags are being set to a default value somewhere. After messing around with this a bit, I got Regarding VanillaJavaBuilder, I think the limitation is that there's no good way to ensure -source/-target aren't being passed to javac, it seems like they always get set to a default value. bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java Lines 305 to 316 in 90b0714
Would it make sense to use this postprocessing in VanillaJavaBuilder as well? It seems like a good strategy, since there doesn't appear to be another way to remove the default -source/-target values from the arguments to javac. |
I'm going to try to remove those
This should be possible. Did you try setting
It could and we're already doing some pre-processing of the args there: bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/VanillaJavaBuilder.java Line 179 in b59498a
In general though |
Sounds great :)
I didn't, but trying it out it does not appear to work. The following toolchain fails when compiling Java code because Bazel still passes --source to javac alongside --release, with the exception I mentioned earlier:
Here are the relevant parts of the exception:
I have also tried copy-pasting the relevant bits from For reference, this configuration works for me, which should be the same as the default, except it uses
Thank you, this is good to know. I am not building Bazel locally to try this out, instead I copied code from
I agree, if that's feasible. I see the Java version mentioned in defaults in a bunch of places (e.g. |
@srdo-humio Do you mind sharing the setup you have working? I'm in a similar need. |
@guw It's the bit I posted above.
Put that in a bazel file somewhere, then register that toolchain in your WORKSPACE, e.g.
|
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 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
I was under the impression that the Java 9+
--release
compiler flag will link against the provided platform version. But as of version 19.0 this does not seem to be the case with Bazel.The following code compiles fine with the
--release 7
javacopt even though it uses a Java 9 API method:Main.java
BUILD
$ bazel build --javacopt="--release 7" / --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 / --java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 / //test/...
Is this intentional or am I doing something wrong? Is there a best practice to compile against older Java versions with Bazel?
I would expect that the compilation fails with some message like
(this is what Ant shows when trying to compile the same)
There is another oddity, not sure if it is related. Bazel shows the following warning upon building:
warning: could not find a JDK 8 bootclasspath in external/local_jdk, falling back to --release
I am using Bazel 0.19.0 on Debian Linux. $PATH and $JAVA_HOME point to Oracle 9.0.4
The text was updated successfully, but these errors were encountered: