Make rules_java backwards compatible with Bazel 6.3.0

Copybara Import from https://github.com/bazelbuild/rules_java/pull/210

BEGIN_PUBLIC
Make rules_java backwards compatible with Bazel 6.3.0 (#210)

Move bootstrap_toolchain_type into rules_java. There are no uses outside
of rules_java. This fixes compatiblity with Bazel 6.3.0, which doesn't
have the definition.

Add back `_allowlist_function_transition`. Older versions of Bazel require it.

Add Bazel 6.3.0 to the CI.

Remove a couple of broken targets from toolchains/BUILD. Those were
broken becuase old JDKs were removed.

Closes #210
END_PUBLIC

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_java/pull/210 from comius:backward-compatible-rules_java 393f270312cbb13fa5bc7807b93cf95f1e7b3969
PiperOrigin-RevId: 670415171
Change-Id: I7f42cc92bb7285cb51a2a1185695451a644d5b30
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 331d1e7..1a49318 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -70,4 +70,19 @@
     platform: windows
     build_flags:
       - "--config=bzlmod"
-    build_targets: *build_targets_bzlmod
\ No newline at end of file
+    build_targets: *build_targets_bzlmod
+  ubuntu2004_bazel630:
+    name: "Bazel 6.3.0"
+    bazel: 6.3.0
+    platform: ubuntu2004
+    build_targets: *build_targets
+  macos_bazel630:
+    name: "Bazel 6.3.0"
+    bazel: 6.3.0
+    platform: macos
+    build_targets: *build_targets
+  windows_bazel630:
+    name: "Bazel 6.3.0"
+    bazel: 6.3.0
+    platform: windows
+    build_targets: *build_targets
diff --git a/.bazelversion b/.bazelversion
deleted file mode 100644
index 66ce77b..0000000
--- a/.bazelversion
+++ /dev/null
@@ -1 +0,0 @@
-7.0.0
diff --git a/MODULE.bazel b/MODULE.bazel
index 26dbcee..775caf9 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,8 +1,7 @@
 module(
     name = "rules_java",
     version = "7.9.1",
-    # Requires @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type.
-    bazel_compatibility = [">=7.0.0"],
+    bazel_compatibility = [">=6.2.0"],
     compatibility_level = 1,
 )
 
diff --git a/toolchains/BUILD b/toolchains/BUILD
index 06d7201..b7252a4 100644
--- a/toolchains/BUILD
+++ b/toolchains/BUILD
@@ -66,8 +66,8 @@
 #
 # Toolchains of this type are only consumed internally by the bootclasspath rule and should not be
 # accessed from Starlark.
-# TODO: migrate away from using @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type ?
-# toolchain_type(name = "bootstrap_runtime_toolchain_type")
+
+toolchain_type(name = "bootstrap_runtime_toolchain_type")
 
 # Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime)
 java_runtime_alias(name = "current_java_runtime")
@@ -294,18 +294,6 @@
 )
 
 java_runtime_version_alias(
-    name = "remotejdk_15",
-    runtime_version = "remotejdk_15",
-    visibility = ["//visibility:public"],
-)
-
-java_runtime_version_alias(
-    name = "remotejdk_16",
-    runtime_version = "remotejdk_16",
-    visibility = ["//visibility:public"],
-)
-
-java_runtime_version_alias(
     name = "remotejdk_17",
     runtime_version = "remotejdk_17",
     visibility = ["//visibility:public"],
diff --git a/toolchains/default_java_toolchain.bzl b/toolchains/default_java_toolchain.bzl
index b3d4d28..e63b7c8 100644
--- a/toolchains/default_java_toolchain.bzl
+++ b/toolchains/default_java_toolchain.bzl
@@ -208,7 +208,7 @@
             tags = ["manual"],
         )
 
-_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type")
+_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("//toolchains:bootstrap_runtime_toolchain_type")
 
 # Opt the Java bootstrap actions into path mapping:
 # https://github.com/bazelbuild/bazel/commit/a239ea84832f18ee8706682145e9595e71b39680
diff --git a/toolchains/java_toolchain_alias.bzl b/toolchains/java_toolchain_alias.bzl
index 8d8a7e4..3488925 100644
--- a/toolchains/java_toolchain_alias.bzl
+++ b/toolchains/java_toolchain_alias.bzl
@@ -85,6 +85,9 @@
     toolchains = ["@bazel_tools//tools/jdk:runtime_toolchain_type"],
     attrs = {
         "runtime_version": attr.string(mandatory = True),
+        "_allowlist_function_transition": attr.label(
+            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+        ),
     },
     cfg = _java_runtime_transition,
 )
diff --git a/toolchains/local_java_repository.bzl b/toolchains/local_java_repository.bzl
index ae5f82f..d4c6029 100644
--- a/toolchains/local_java_repository.bzl
+++ b/toolchains/local_java_repository.bzl
@@ -110,7 +110,7 @@
     native.toolchain(
         name = "bootstrap_runtime_toolchain_definition",
         target_settings = [":%s_settings_alias" % name],
-        toolchain_type = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type"),
+        toolchain_type = Label("//toolchains:bootstrap_runtime_toolchain_type"),
         toolchain = runtime_name,
     )
 
@@ -268,7 +268,7 @@
 toolchain(
    name = "bootstrap_runtime_toolchain_definition",
    target_settings = [":localjdk_setting"],
-   toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type",
+   toolchain_type = "@rules_java//tools/jdk:bootstrap_runtime_toolchain_type",
    toolchain = ":jdk",
 )
 '''
diff --git a/toolchains/remote_java_repository.bzl b/toolchains/remote_java_repository.bzl
index 65bbe48..a2535d3 100644
--- a/toolchains/remote_java_repository.bzl
+++ b/toolchains/remote_java_repository.bzl
@@ -89,7 +89,7 @@
     # the same configuration, this constraint will not result in toolchain resolution failures.
     exec_compatible_with = {target_compatible_with},
     target_settings = [":version_or_prefix_version_setting"],
-    toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type",
+    toolchain_type = "@rules_java//toolchains:bootstrap_runtime_toolchain_type",
     toolchain = "{toolchain}",
 )
 """.format(