-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Flag: --incompatible_use_toolchain_resolution_for_java_rules
Available since: 5.0.0
Will be flipped in: 5.0.0
Tracking issue: #4592
Motivation
Currently, Java rules find their Java toolchain and JDK using the --javabase / --java_toolchain / --host_javabase / --host_java_toolchain command line options. This will be changed to use platform-based toolchain resolution so as to be consistent with the rest of Bazel and to support multiple platforms more easily.
Migration notes
For --javabase with old values:
@local_jdk://jdk@remotejdk11_{linux,window,darwin}_{cpu}//:jdk@remotejdk14_{linux,window,darwin}//:jdk@remotejdk15_{linux,window,darwin}.*//:jdk
Replace the flag with --java_runtime_version={local_jdk,remotejdk_14,remotejdk_15}.
For --java_toolchain with old values:
@bazel_tools//tools/jdk:toolchain,@bazel_tools_hostjdk8,@bazel_tools//jdk:legacy_toolchain,@bazel_tools//tools/jdk:remote_toolchain,@bazel_tools//tools/jdk:toolchain_java_{ver},@remote_java_tools_xxx//:toolchain,@remote_java_tools_xxx//:toolchain_jdk_11,@remote_java_tools_xxx//:toolchain_jdk_14,@remote_java_tools_xxx//:toolchain_jdk_15
Replace the flag with --java_language_version={8,...,15}
Migration of more advanced cases
For --javabase=@bazel_tools//tools/jdk:absolute_javabase, use local_java_repositoy in the WORKSPACE file.
For custom --javabase labels, do the following:
- replace
http_archivewithremote_java_repository:
remote_java_repository(
name = ...
sha256 = ...
strip_prefix = ...
urls = ...
prefix = "myjdk",
version = "11",
exec_compatible_with = ["@platforms//cpu:arm", "@platforms//os:linux"]
)- replace the old flag with
--java_runtime_versionwith the specifiedversionorprefix_versionvalue (for example--java_runtime_version=myjdk_11).
For old --java_toolchain values:
@bazel_tools//tools/jdk:toolchain_vanilla@remote_java_tools_xxx//:prebuilt_toolchain- custom label
- add custom toolchain definition to a
BUILDfile (or replace custom target):
default_java_toolchain(
name = "mytoolchain",
configuration = "PREBUILT_TOOLCHAIN_CONFIGURATION"
#or "VANILLA_TOOLCHAIN_CONFIGURATION"
...
)- register custom toolchain in the
WORKSPACEor use configuration flag--extra_toolchains.
RBE migration
- Update the version of bazel_toolchains.
- Add following flags to
.bazelrcaffecting remote configuration:
build:remote --java_runtime_version=rbe_jdk # Uses JDK installed on docker, configured by bazel_toolchains
build:remote --tool_java_runtime_version=rbe_jdk
build:remote --extra_toolchains=@rbe_ubuntu1804//java:all # Optional: uses JDK installed on docker to compile
- In case the sources are not Java 8, also add:
build --java_language_version=11
build --tool_java_language_version=11
- Once Bazel 4.1.0 is released and used on RBE Remove
--{,host}javabaseand--{,host}_javatoolchainflags.