Repository navigation
bazel: Upgrade rules_java to 9.1.0 in WORKSPACE to support JDK 25 - #13140
Conversation
|
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? |
|
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.
f033c66 to
20f92cf
Compare
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! |
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.