Skip to content

bazel: Upgrade rules_java to 9.1.0 in WORKSPACE to support JDK 25 - #13140

Merged
jdcormie merged 1 commit into
grpc:masterfrom
jdcormie:bazel-pin-jdk
Oct 28, 2026
Merged

jdcormie merged 1 commit into
grpc:masterfrom
jdcormie:bazel-pin-jdk

Conversation

@jdcormie

@jdcormie jdcormie commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Bazel's default --java_runtime_version is local_jdk, so the Java runtime used by the build was whatever JDK happened to be the host default. The javac toolchain, however, runs on a downloaded JDK 21, and rules_java 8.x (used by the WORKSPACE build) has nothing newer. So on any host whose default JDK is newer than 21 the build fails:

error: [BazelJavaConfiguration] The Java 21 runtime used to run javac is
not recent enough to compile for the Java 25 runtime in external/local_jdk.

This started failing in CI when GitHub's ubuntu-latest runner image moved from Ubuntu 24.04 (default JDK 17) to 26.04 (default JDK 25), but it equally affects developers following COMPILING.md on a recent distro.

Use the downloaded remotejdk_21 for both the target and tool runtime so the build no longer depends on the host JDK. JDK 21 is already fetched as the javac tool runtime, so this adds no new downloads, and it is the newest JDK in the Gradle test matrix. Installing a JDK in CI via setup-java (as the Gradle jobs do) would fix CI but not local builds. examples/ is a separate workspace with its own .bazelrc, so apply the same flags there.

@jdcormie jdcormie changed the title bazel: Pin Java runtime to remotejdk_21 instead of local_jdk bazel: Fix build on hosts with JDK newer than 21 Oct 27, 2026
@jdcormie
jdcormie requested a review from ejona86 October 28, 2026 00:24
@ejona86

ejona86 commented Oct 28, 2026

Copy link
Copy Markdown
Member

I don't think we should do this. This prevents us from testing compatibility with other JDKs (because our users can use a different JDK). Normally we just upgrade something when this happens. Is there any problem with upgrading to rules_java 9.x? But even if staying on 8.x, 8.16.1 specifically mentions JDK 25, so did you try that version?

@ejona86
ejona86 requested a review from kannanjgithub October 28, 2026 16:17
@ejona86

ejona86 commented Oct 28, 2026

Copy link
Copy Markdown
Member

Hmm... "bazel build ..." just ran fine with Bazel 9.3.1 and JDK 25.0.4.1. Is something else going on?

The WORKSPACE build pinned rules_java 8.15.2, whose newest bundled JDK is
21. Bazel's default --java_runtime_version is local_jdk, so on a host whose
default JDK is newer than 21 the javac toolchain cannot target it and the
build fails:

  error: [BazelJavaConfiguration] The Java 21 runtime used to run javac is
  not recent enough to compile for the Java 25 runtime in external/local_jdk.

This started failing in CI when GitHub's ubuntu-latest runner image moved
from Ubuntu 24.04 (default JDK 17) to 26.04 (default JDK 25). The bzlmod
build was unaffected because MODULE.bazel already uses rules_java 9.1.0.

Upgrade the WORKSPACE build to the same rules_java 9.1.0. Since 8.16,
rules_java_deps.bzl loads @bazel_features, so bazel_features_deps() must
now run before rules_java_dependencies(). examples/ has its own WORKSPACE,
so apply the same change there.
@jdcormie jdcormie changed the title bazel: Fix build on hosts with JDK newer than 21 bazel: Upgrade rules_java to 9.1.0 in WORKSPACE to support JDK 25 Oct 28, 2026
@jdcormie

Copy link
Copy Markdown
Member Author

I don't think we should do this. This prevents us from testing compatibility with other JDKs (because our users can use a different JDK). Normally we just upgrade something when this happens. Is there any problem with upgrading to rules_java 9.x? But even if staying on 8.x, 8.16.1 specifically mentions JDK 25, so did you try that version?

OK good point. I wrote the PR thinking that the only thing that mattered was the built grpc-java jar. I forgot that dependent apps using bazel actually build grpc-java from source for themselves using their own JDK.

Regarding "something else going on": yes, you must have tested using bzlmod but the problem was in WORKSPACE mode which currently pins rules_java 8.15.2 whose newest JDK is 21. I went with 9.1.0 rather than 8.16.1 so both modes use a 9.x rules_java.

Thanks!

@jdcormie
jdcormie merged commit 3b660ac into grpc:master Oct 28, 2026
18 checks passed
@jdcormie
jdcormie deleted the bazel-pin-jdk branch October 28, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants