← Back to team overview

bazel-team team mailing list archive

Bazel 4 / Debian / Java 17

 

Hello,

Tried to make Debian based containers for Bazel based Java software, and
came across you also struggling with it a bit as some of the command line
args that old of a Bazel blindly assumes any Java will eat are not eaten by
Java 17 anymore.

https://groups.google.com/g/bazel-discuss/c/bYRDY_Vzq9I

Found a somewhat elegant way through the trouble, where one does not need
to modify Bazel itself, but one can patch the build files of the software
one is trying to build.

The BUILD file needs the following:

load(
"@bazel_tools//tools/jdk:default_java_toolchain.bzl",
"default_java_toolchain",
"JDK9_JVM_OPTS",
)

default_java_toolchain(
name = "debian_toolchain",
jvm_opts = JDK9_JVM_OPTS + [ "-XX:+IgnoreUnrecognizedVMOptions" ],
)

This takes the default toolchain definition and extends it by adding one
more JVM option to it, which makes the JVM ignore any unknown args having
been fed to it.

This is safe to do in this case, as the old parameter being fed to it was
added in early Java 9 development cycle times as an optimisation and it was
expected to have gone away by the time Java 10 comes around. Seems it never
got cleaned up and it's still there.

https://github.com/bazelbuild/bazel/commit/3842bd39e10612c7eef36c6048407e81bcd0a8fb

With this in place, one can make the build use that new toolchain either by
two command line args, --java_toolchain and --host_java_toolchain or by
supplying a .bazelrc file where these are defined.

build --java_toolchain=//:debian_toolchain
build --host_java_toolchain=//:debian_toolchain

Hopefully not reiterating the obvious for you.

-- Joni Orponen