bazel: incompatible_use_toolchain_resolution_for_java_rules: use toolchain resolution for Java rules
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_archive
withremote_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_version
with the specifiedversion
orprefix_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_toolchain
- custom label
- add custom toolchain definition to a
BUILD
file (or replace custom target):
default_java_toolchain(
name = "mytoolchain",
configuration = "PREBUILT_TOOLCHAIN_CONFIGURATION"
#or "VANILLA_TOOLCHAIN_CONFIGURATION"
...
)
- register custom toolchain in the
WORKSPACE
or use configuration flag--extra_toolchains
.
RBE migration
- Update the version of bazel_toolchains.
- Add following flags to
.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
- 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}javabase
and--{,host}_javatoolchain
flags.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 34 (27 by maintainers)
Links to this issue
Commits related to this issue
- Rename --experimental_use_toolchain_resolution_for_java_rules to --incompatible_use_toolchain_resolution_for_java_rules. This is so that it can be re-used for the Bazel flag flip. The bug for the fl... — committed to bazelbuild/bazel by lberki 5 years ago
- Flip incompatible_use_toolchain_resolution_for_java_rules flag. RELNOTES[INC]: flipped incompatible_use_toolchain_resolution_for_java_rules, see #7849 Closes #12812. PiperOrigin-RevId: 351593322 — committed to bazelbuild/bazel by comius 3 years ago
- Release 5.0.0-pre.20210510.2 (2021-05-31) Baseline: 8a42645ec500874b0440475763ab680d5efc1e6a Cherry picks: + e3c78c4eeaf4e8db3c22aa71c6c1578cb48c8dcc: Ensure that test status artifacts are ... — committed to bazelbuild/bazel by a-googler 3 years ago
- Release 5.0.0-pre.20210810.4 (2021-08-19) Baseline: ead44955c5cf02d94152f2cf3462c40ee6659594 Cherry picks: + 99a85e79a11cef98d0e08db21ab94833398381af: Automated rollback of commit 92f7... — committed to bazelbuild/bazel by a-googler 3 years ago
- Release 5.0.0-pre.20210826.1 (2021-09-03) Baseline: f53c389dbd4b0ae66307e9bd4a72b36b3d284ec3 Incompatible changes: - Removing java_common.javac_jar Starlark call. - native.existing_rule now ret... — committed to bazelbuild/bazel by a-googler 3 years ago
- Report an error when deprecated no-op Java toolchain flags are used without the new ones. Related to https://github.com/bazelbuild/bazel/issues/7849 Fixes https://github.com/bazelbuild/bazel/issues/1... — committed to comius/bazel by comius 3 years ago
- Report an error when deprecated no-op Java toolchain flags are used without the new ones. Related to https://github.com/bazelbuild/bazel/issues/7849 Fixes https://github.com/bazelbuild/bazel/issues/1... — committed to bazelbuild/bazel by comius 3 years ago
- Release 6.0.0-pre.20211117.1 (2021-12-07) Baseline: e5b3536583f742e0dda9fd377dffbda3c1e3d366 Incompatible changes: - Removing java_common.javac_jar Starlark call. - native.existing_rule now ret... — committed to bazelbuild/bazel by a-googler 3 years ago
- Release 6.0.0-pre.20211117.1 (2021-12-07) Baseline: e5b3536583f742e0dda9fd377dffbda3c1e3d366 Incompatible changes: - Removing java_common.javac_jar Starlark call. - native.existing_rule now ret... — committed to Bencodes/bazel by a-googler 3 years ago
- Bazel: Switch to using toolchain resolution for java rules Bump Bazel version to release 5.0.0. In this new Bazel release, --incompatible_use_toolchain_resolution_for_java_rules is flipped, that mean... — committed to GerritCodeReview/jgit by davido 3 years ago
- Revert "Pin Jazzer to pre-Bazel 5 update (#7192)" This reverts commit d3d1e1f838e2d996671db14ef650250aba06f094. Also fixes a typo in the Java runtime version specifier for Bazel 5: localjdk_15 shoul... — committed to CodeIntelligenceTesting/oss-fuzz by fmeum 2 years ago
- Revert "Pin Jazzer to pre-Bazel 5 update (#7192)" (#7194) This reverts commit d3d1e1f838e2d996671db14ef650250aba06f094. Also fixes a typo in the Java runtime version specifier for Bazel 5: localj... — committed to google/oss-fuzz by fmeum 2 years ago
- Revert "Pin Jazzer to pre-Bazel 5 update (#7192)" (#7194) This reverts commit d3d1e1f838e2d996671db14ef650250aba06f094. Also fixes a typo in the Java runtime version specifier for Bazel 5: localj... — committed to google/oss-fuzz by fmeum 2 years ago
- Bazel: Switch to using toolchain resolution for java rules Bump Bazel version to release 5.0.0. In this new Bazel release, --incompatible_use_toolchain_resolution_for_java_rules is flipped, that mean... — committed to GerritCodeReview/gerrit by davido 4 years ago
- Upgrade bazel to 5.0.0 These are the commands I used to generate the bazel xz file: $ wget 'https://github.com/bazelbuild/bazel/releases/download/5.0.0/bazel-5.0.0-linux-x86_64' $ xz bazel-5... — committed to frc971/971-Robot-Code by philsc 2 years ago
- Use java toolchains The --javabase, and --java_toolchain options are removed in Bazel 5.0. https://github.com/bazelbuild/bazel/issues/7849 Also removed javacopt as the default java options includes ... — committed to Flank/mirror-goog-studio-main by deleted user 2 years ago
- Update Java flags as per https://github.com/bazelbuild/bazel/issues/7849 migration notes — committed to thundergolfer/uni by deleted user 2 years ago
- Revert "Pin Jazzer to pre-Bazel 5 update (#7192)" (#7194) This reverts commit d3d1e1f838e2d996671db14ef650250aba06f094. Also fixes a typo in the Java runtime version specifier for Bazel 5: localj... — committed to MartinPetkov/oss-fuzz by fmeum 2 years ago
- Release 5.3.2 (2022-10-19) Baseline: 8d66a4171baddcbe1569972f019e54130111202c Cherry picks: + becd1494481b96d2bc08055d3d9d4d7968d9702e: Remote: Cache merkle trees + d7628e1b566be353fe717... — committed to bazelbuild/bazel by a-googler 2 years ago
- Release 5.3.2 (2022-10-19) Baseline: 8d66a4171baddcbe1569972f019e54130111202c Cherry picks: + becd1494481b96d2bc08055d3d9d4d7968d9702e: Remote: Cache merkle trees + d7628e1b566be353fe717... — committed to bazelbuild/bazel by a-googler 2 years ago
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!
This breaks for me when I upgraded one of my repositories and none of the fixes here worked.
Someone else has a reproducible example here which breaks for
bazel coverage
: https://github.com/bazelbuild/bazel/issues/15035We were able to make it work starting from Bazel 5.0.0. See this pending CL: [1].
[1] https://gerrit-review.googlesource.com/c/gerrit/+/291864
Done.
@comius
On Bazel@HEAD (32fc451600b6e94a015263eb1c8a63e974f6f4cc), after flipping of:
--incompatible_use_toolchain_resolution_for_java_rules
alltoolchain
parameters don’t seem to have any effect. IOW, if I am using (on Gerrit project):Then it works, but it doesn’t produce Java major byte version 59:
To make it work again, I have to explicitly un-flip:
--incompatible_use_toolchain_resolution_for_java_rules=false
, only then it works as expected:I would rather expect that
toolchain
options are not silently ignored, but rather rejected, as usually, right?