Flag: --incompatible_use_toolchain_resolution_for_java_rules
Available since: 4.1.0
Will be flipped in: 4.1.0
Tracking issue: #4592
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.
For --javabase with old values:
@local_jdk://jdk@remotejdk11_{linux,window,darwin}_{cpu}//:jdk@remotejdk14_{linux,window,darwin}//:jdk@remotejdk15_{linux,window,darwin}.*//:jdkReplace the flag with --java_runtime_version={localjdk,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_15Replace the flag with --java_language_version={8,...,15}
For --javabase=@bazel_tools//tools/jdk:鈥媋bsolute_javabase, use local_java_repositoy in the WORKSPACE file.
For custom --javabase labels, do the following:
http_archive with remote_java_repository:remote_java_repository(
name = ...
sha256 = ...
strip_prefix = ...
urls = ...
prefix = "myjdk",
version = "11",
exec_compatible_with = ["@platforms//cpu:arm", "@platforms//os:linux"]
)
--java_runtime_version with the specified version or prefix_version value (for example --java_runtime_version=myjdk_11).For old --java_toolchain values:
@bazel_tools//tools/jdk:toolchain_vanilla@remote_java_tools_xxx//:prebuilt_toolchainBUILD file (or replace custom target):default_java_toolchain(
name = "mytoolchain",
configuration = "PREBUILT_TOOLCHAIN_CONFIGURATION"
#or "VANILLA_TOOLCHAIN_CONFIGURATION"
...
)
WORKSPACE or use configuration flag --extra_toolchains..bazelrc affecting 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
build --java_language_version=11
build --tool_java_language_version=11
--{,host}javabase and --{,host}_javatoolchain flags.@lberki can you add migration notes for this? bazelisk's --migrate hits this and it appears that protobuf fails to build with this flag enabled with 0.25.2:
% bazel build :all --incompatible_use_toolchain_resolution_for_java_rules
INFO: Build option --incompatible_use_toolchain_resolution_for_java_rules has changed, discarding analysis cache.
ERROR: /Users/ksmiley/dev/protobuf/BUILD:636:1: in java_library rule //:protobuf_java: header compilation was requested but it is not supported by the current Java toolchain '@bazel_tools//tools/jdk:dummy_toolchain'; see the java_toolchain.header_compiler attribute
ERROR: Analysis of target '//:java_toolchain' failed; build aborted: Analysis of target '//:protobuf_java' failed; build aborted
INFO: Elapsed time: 0.604s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 2453 targets configured)
This flag breaks a lot of downstream projects, migration notes are missing, and the error message is unclear. I'm going to remove the migration flag for now.
This flag breaks a lot of downstream projects, migration notes are missing, and the error message is unclear. I'm going to remove the migration flag for now.
There was some discussion of this in cl/240945826, and my understanding was that this met the policy requirements for adding an --incompatible_* flag. Has the policy changed?
I think the plan is still to add migration notes and push forward on this migration soon.
cc @iirina @hlopko
Correct, we'll add migration instructions and start migrating soon. First we need to introduce Java constraint settings and values. @iirina is well on top of things.
The following java_toolchain targets are exposed by Bazel:
@bazel_tools//tools/jdk:toolchain@bazel_tools//tools/jdk:toolchain_hostjdk8@bazel_tools//tools/jdk:legacy_toolchain@bazel_tools//tools/jdk:toolchain_vanilla@bazel_tools//tools/jdk:toolchain_java{8, 9, 10, 11}Everyone using --java_toolchain/--host_java_toolchain pointing at any of these targets have to migrate. I'll come back with migration details for every of these targets.
Removing the bazel 1.0 label and extending the migration window.
Since https://github.com/bazelbuild/rules_java/pull/8 is not merged, this does not seem ready for migration. Should the migration tags be removed?
Yup, thanks!
Hi, is this and the above PR dead?
Assigning to @lberki to determine priority.
What is the status of this? It is really confusing right now, because docs seem to indicate we can use Java toolchains but since the PR is not merged this does not work. I would love to be able to use toolchains with Java rules!
Any info would be very much appreciated! Thank you.
cc @comius
Most helpful comment
What is the status of this? It is really confusing right now, because docs seem to indicate we can use Java toolchains but since the PR is not merged this does not work. I would love to be able to use toolchains with Java rules!