I am evaluating Bazel and trying to configure it so that it builds and tests my scala project using a different JDK than the one it has been built with.
These are the relevant lines from the output of my bazel info
:
java-home: /nix/store/09x4mnxfzppwq1yjaakrfa6aj3rp7sw8-openjdk-11.0.4-ga/lib/openjdk
java-runtime: OpenJDK Runtime Environment (build 11.0.3-internal+0-adhoc..jdk11u-jdk-11.0.3-ga) by Oracle Corporation
java-vm: OpenJDK 64-Bit Server VM (build 11.0.3-internal+0-adhoc..jdk11u-jdk-11.0.3-ga, mixed mode) by Oracle Corporation
max-heap-size: 8325MB
package_path: %workspace%
release: release 1.1.0- (@non-git)
While my package manager seems to have built Bazel using a fairly recent version of openjdk, the project I want to build/test should instead use a JDK I have installed under: /usr/lib/jvm/java-8-openjdk
.
By digging into various github issues, I ended up with the following solution, which allows me to get a green build:
bazel test
--define=ABSOLUTE_JAVABASE=/usr/lib/jvm/java-8-openjdk
--host_javabase=@bazel_tools//tools/jdk:absolute_javabase
--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
--java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
--test_timeout=10 --test_output=all //...
However, I am still confused on the following:
- How can I permanently set this option on a project basis, so that I don't have to supply them all the times?
- Can I do so in such a way that the intellij Bazel plugin will automatically pick it up?
- What are the settings above overriding exactly, and is there a simpler way to achieve the same result?