From 88a1a5aa23b7843d9e019b5b4581a3d6ac166f17 Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Fri, 29 Nov 2024 17:52:06 +0200 Subject: [PATCH] [bazel + java] Use a transition to target Java 11 for our maven artifacts This allows us to use Java 21 elsewhere in the repo where it might be useful (Tests! Tests! Tests!) without needing to monkey around with special flags. --- .bazelrc | 15 +++++++-------- MODULE.bazel | 1 + java/private/export.bzl | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.bazelrc b/.bazelrc index f0031fc19eab8..4132eeca42710 100644 --- a/.bazelrc +++ b/.bazelrc @@ -20,14 +20,13 @@ build --flag_alias=headless=//common:headless # Set the default java toolchain -build --java_language_version=17 -build --java_runtime_version=remotejdk_17 -build --tool_java_language_version=17 -build --tool_java_runtime_version=remotejdk_17 - -# We target java 11 by default - -build --javacopt="--release 11" +# This is the version of Java used by Selenium's build and tooling. +# We use a transition in `export.bzl` to set the version of Java we +# target for the binaries we ship to 11. +build --java_language_version=21 +build --java_runtime_version=remotejdk_21 +build --tool_java_language_version=21 +build --tool_java_runtime_version=remotejdk_21 # Require java dependencies to be used and first-order diff --git a/MODULE.bazel b/MODULE.bazel index ffb74a8cfbaf4..9c688dd468dd2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -26,6 +26,7 @@ bazel_dep(name = "rules_pkg", version = "0.10.1") bazel_dep(name = "rules_python", version = "0.33.0") bazel_dep(name = "rules_proto", version = "6.0.0") bazel_dep(name = "rules_ruby", version = "0.13.0") +bazel_dep(name = "with_cfg.bzl", version = "0.6.0") linter = use_extension("@apple_rules_lint//lint:extensions.bzl", "linter") linter.configure( diff --git a/java/private/export.bzl b/java/private/export.bzl index 1d3e9b0498b46..0e60a8f966b69 100644 --- a/java/private/export.bzl +++ b/java/private/export.bzl @@ -6,7 +6,12 @@ load( load("@rules_jvm_external//private/rules:maven_bom_fragment.bzl", "maven_bom_fragment") load("@rules_jvm_external//private/rules:maven_project_jar.bzl", "maven_project_jar") load("@rules_jvm_external//private/rules:maven_publish.bzl", "maven_publish") -load("//java/private:module.bzl", "java_module") +load("@with_cfg.bzl", "with_cfg") +load("//java/private:module.bzl", _java_module = "java_module") + +_builder = with_cfg(_java_module) +_builder.set("java_language_version", "11").set("java_runtime_version", "remotejdk_11") +java_module, _ = _builder.build() def java_export( name,