Closed davido closed 6 years ago
In 0.16.1 default_java_toolchain.jvm_opts
is defaulting to the JDK 8-compatible jvm flags. You can see that @bazel_tools//tools/jdk:toolchain_java9
overrides them:
Overriding them in your custom toolchain will make it work with 0.16.1:
diff --git a/tools/BUILD b/tools/BUILD
index e11db8c64e..890ed0cb50 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -1,4 +1,4 @@
-load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")
+load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain", "JDK9_JVM_OPTS")
py_binary(
name = "merge_jars",
@@ -11,6 +11,7 @@ py_binary(
default_java_toolchain(
name = "error_prone_warnings_toolchain",
bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"],
+ jvm_opts = JDK9_JVM_OPTS,
package_configuration = [
":error_prone",
],
That won't be compatible with 0.17, though, since JDK9_JVM_OPTS
no longer exists. I guess you could define different toolchains for 0.16.1 and 0.17 as a work-around.
I can't reproduce the problem with 0.17rc1. I run into https://github.com/bazelbuild/bazel/issues/5997#issuecomment-416124876 and #5989, but not the error you reported. How do I repro that?
I confirm, thar the suggested workaround works as expected on 0.16.1, but that breaks 0.17.rc1, because now I get:
$ bazel build --java_toolchain //tools:error_prone_warnings_toolchain //java/com/google/gerrit/server:server
ERROR: /home/davido/projects/gerrit2/tools/BUILD:1:1: file '@bazel_tools//tools/jdk:default_java_toolchain.bzl' does not contain symbol 'JDK9_JVM_OPTS'
ERROR: /home/davido/projects/gerrit2/tools/BUILD:18:16: Traceback (most recent call last):
File "/home/davido/projects/gerrit2/tools/BUILD", line 15
default_java_toolchain(name = "error_prone_warnings_too...", <4 more arguments>)
File "/home/davido/projects/gerrit2/tools/BUILD", line 18, in default_java_toolchain
JDK9_JVM_OPTS
name 'JDK9_JVM_OPTS' is not defined
Is there a way to import things conditionally?
Reproducer: https://gerrit-review.googlesource.com/c/gerrit/+/194045
That won't be compatible with 0.17, though, since
JDK9_JVM_OPTS
no longer exists.I confirm, thar the suggested workaround works as expected on 0.16.1, but that breaks 0.17.rc1
Right. I'm not aware of a conditional import mechanism. You could define different toolchains for 0.16 and 0.17, or inline those JVM flags instead of using the constant.
Is the core dump you mentioned seeing with 0.17rc1 in your original comment reproducible, or was that a transient failure?
I can't reproduce the problem with 0.17rc1.
[...]
Is the core dump you mentioned seeing with 0.17rc1 in your original comment reproducible, or was that a transient failure?
Never mind, I re-downloaded 0.17rc1 and confirmed it works with restrictions, that you've mentioned. Apparently I had the old 0.17rc1 download, that was re-cut recently. Sorry that I messed that up.
An alternative workaround should then be to respect https://docs.bazel.build/versions/master/install-compile-source.html and use JDK 8. I can confirm that this works: I just built 0.16.1 successfully on openSUSE Leap 15.0 with JDK 8.
(I uninstalled JDKs 10 and 11 as openSUSE doesn't have update-java-alternatives and changing a handful of alternatives with update-alternatives seems too much hassle.)
Trying to use custom
java_toolchain
is failing on latest released Bazel version (0.16.1):On unreleased 0.17rc1 there is another error:
On Bazel@HEAD (2894b3005693d1318a28b66d22ca39eb7a34077c) it seems to work.
Reproducer: https://gerrit-review.googlesource.com/c/gerrit/+/194045.