You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bump to rules_java 7.9.0 for Bazel 7 compatibility
Updated rules_java to 7.9.0 to fix errors of the following type under
Bazel 7.2.1:
```txt
ERROR: test/BUILD:640:10:
While resolving toolchains for target //test:jar_lister (096dcc8):
invalid registered toolchain
'@remote_jdk8_linux_aarch64_toolchain_config_repo//:bootstrap_runtime_toolchain':
no such target
'@@remote_jdk8_linux_aarch64_toolchain_config_repo//:bootstrap_runtime_toolchain':
target 'bootstrap_runtime_toolchain' not declared in package '' defined by
.../external/remote_jdk8_linux_aarch64_toolchain_config_repo/BUILD.bazel
ERROR: Analysis of target '//test:jar_lister' failed; build aborted
```
Also removed the seemingly unused `rules_java_extra` stanza from
`WORKSPACE`.
---
Though `rules_java` version 7.12.1 is available, and largely works with
this repo when using Bazel 7.3.2, it requires a few temporary
workarounds. (As I write this, 8.0.0 came out just a few hours ago and I
haven't tried it.) Rather than commit the workarounds, upgrading only to
7.9.0 now seems less crufty.
Though this commit only updates Bazel to 7.2.1, I suspect it's probably
the same basic problem at play.
What follows is a very detailed explanation of what happens with 7.12.1
with Bazel 7.3.2, just to have it on the record.
---
The workaround is to change a few toolchain and macro file targets from
`@bazel_tools//tools/jdk:` to `@rules_java//toolchains:`. This isn't a
terribly bad or invasive workaround, but `@bazel_tools//tools/jdk:` is
clearly the canonical path. Best to keep it that way, lest we build up
technical debt.
Without the workaround, these targets would fail:
- //test/src/main/resources/java_sources:CompiledWithJava11
- //test/src/main/resources/java_sources:CompiledWithJava8
- //test/toolchains:java21_toolchain
- //test:JunitRuntimePlatform
- //test:JunitRuntimePlatform_test_runner
- //test:scala_binary_jdk_11
with this error:
```txt
ERROR: .../external/rules_java_builtin/toolchains/BUILD:254:14:
While resolving toolchains for target
@@rules_java_builtin//toolchains:platformclasspath (096dcc8):
No matching toolchains found for types
@@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type.
```
This appears to be a consequence of both upgrading the Bazel version to
7.3.2 and updating `rules_java` to 7.12.1. The `rules_java_builtin` repo
is part of the `WORKSPACE` prefix that adds implicit dependencies:
- https://bazel.build/external/migration#builtin-default-deps
This repo was added to 7.0.0-pre.20231011.2 in the following change,
mapped to `@rules_java` within the scope of the `@bazel_tools` repo:
- bazelbuild/bazel: Add rules_java_builtin to the users of Java modules
bazelbuild/bazel@ff1abb2
This change tried to ensure `rules_java` remained compatible with
earlier Bazel versions. However, it changed all instances of
`@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` to
`//toolchains:bootstrap_runtime_toolchain_type`:
- bazelbuild/rules_java: Make rules_java backwards compatible with Bazel
6.3.0
bazelbuild/rules_java@30ecf3f
Bazel has bumped `rules_java` in its `workspace_deps.bzl` from 7.9.0 to
7.11.0, but it's only available as of 8.0.0-pre.20240911.1.
- bazelbuild/bazel: Update rules_java 7.11.1 / java_tools 13.8
bazelbuild/bazel#23571bazelbuild/bazel@f92124a
---
What I believe is happening is, under Bazel 7.3.2 and `rules_java`
7.12.1:
- Bazel creates `rules_java` 7.9.0 as `@rules_java_builtin` in the
`WORKSPACE` prefix.
- `@bazel_tools` has `@rules_java` mapped to `@rules_java_builtin` when
initialized during the `WORKSPACE` prefix, during which
`@bazel_tools//tools/jdk` registers `alias()` targets to
`@rules_java` toolchain targets. These aliased toolchains specify
`@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` in their
`toolchains` attribute.
- `WORKSPACE` loads `@rules_java` 7.12.1 and registers all its
toolchains with type
`@rules_java//toolchains:bootstrap_runtime_toolchain_type`.
- Some `@rules_java` rules explicitly specifying toolchains from
`@bazel_tools//tools/jdk` can't find them, because the
`@bazel_tools//tools/jdk` toolchain aliases expect toolchains of type
`@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type`.
This has broken other projects in the same way:
- bazelbuild/bazel: [Bazel CI] Downstream project broken by rules_java
upgrade #23619
bazelbuild/bazel#23619
These problems don't appear under Bzlmod, whereby `@rules_java_builtin`
was never required. This is because `WORKSPACE` executes its statements
sequentially, while Bzlmod builds the module dependency graph _before_
instantiating repositories (within module extensions).
It seems a fix is on the way that removes `@rules_java_builtin` from the
`WORKSPACE` prefix, and adds `@rules_java` to the suffix. At this
moment, though, it's not even in a prerelease:
- bazelbuild/bazel: Remove rules_java_builtin in WORKSPACE prefix
bazelbuild/bazel@7506690
---
Note that the error message matches that from the following resolved
issue, but that issue was for non-Bzlmod child repos when `WORKSPACE`
was disabled.
- bazelbuild/bazel: Undefined @@rules_java_builtin repository with
--noenable_workspace option
bazelbuild/bazel#22754
0 commit comments