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
means that the build must be adapted to toolchain resolution.
Given that new Bazel release also added support for remote JDK 17, add
support for building with remote JDK 17 to produce major byte code
version 61.
Change-Id: I5bc5f640bcd43529f799a8df01ad4a496f0394d3
diff --git a/.bazelrc b/.bazelrc
index b481c64..ac89666 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -3,7 +3,18 @@
build --experimental_strict_action_env
build --action_env=PATH
build --disk_cache=~/.gerritcodereview/bazel-cache/cas
-build --java_toolchain //tools:error_prone_warnings_toolchain_java11
+
+# Builds using remote_jdk11, executes using remote_jdk11 or local_jdk
+build --java_language_version=11
+build --java_runtime_version=remotejdk_11
+build --tool_java_language_version=11
+build --tool_java_runtime_version=remotejdk_11
+
+# Builds using remote_jdk17, executes using remote_jdk17 or local_jdk
+build:java17 --java_language_version=17
+build:java17 --java_runtime_version=remotejdk_17
+build:java17 --tool_java_language_version=17
+build:java17 --tool_java_runtime_version=remotejdk_17
test --build_tests_only
test --test_output=errors
diff --git a/.bazelversion b/.bazelversion
index fcdb2e1..0062ac9 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-4.0.0
+5.0.0
diff --git a/WORKSPACE b/WORKSPACE
index 1753885..b3e0d3f 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -27,6 +27,10 @@
path = "modules/jgit",
)
+register_toolchains("//tools:error_prone_warnings_toolchain_java11_definition")
+
+register_toolchains("//tools:error_prone_warnings_toolchain_java17_definition")
+
maven_jar(
name = "commons-lang3",
artifact = "org.apache.commons:commons-lang3:3.8.1",
diff --git a/tools/BUILD b/tools/BUILD
index ec76f1b..500e197 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -6,11 +6,23 @@
default_java_toolchain(
name = "error_prone_warnings_toolchain_java11",
- source_version = "11",
- target_version = "11",
package_configuration = [
":error_prone",
],
+ source_version = "11",
+ target_version = "11",
+ visibility = ["//visibility:public"],
+)
+
+default_java_toolchain(
+ name = "error_prone_warnings_toolchain_java17",
+ configuration = dict(),
+ java_runtime = "@bazel_tools//tools/jdk:remotejdk_17",
+ package_configuration = [
+ ":error_prone",
+ ],
+ source_version = "17",
+ target_version = "17",
visibility = ["//visibility:public"],
)