Rollforward of https://github.com/bazelbuild/bazel/commit/7e48642db90977d37531053775be5ac9083078b7: Attach local JDK to JVM8_TOOLCHAIN_CONFIGURATION.

This is a partial revert of https://github.com/bazelbuild/bazel/commit/ec29e28a7f729c6a899ad0a75c770c4d174d78af.
The commit support rules_appengine usecase, which needs to supply additional parameters to a toolchain compiling with JDK8.
Previously the whole commit broke repos that are using bazel-toolchains.

Caveat: the downstream still breaks rules_appengine on Java 11 only system (Ubuntu 18.04). I believe this is correct behaviour, because rules_appengine seem to support only Java 8.

Addresses issue: https://github.com/bazelbuild/rules_appengine/issues/119

NEW: changed cquery to query in JVM8_TOOLCHAIN_TEST, this way not triggering toolchain resolution on systems without JDK8

Automated rollback of commit fd44d300d68d8f08a5e3849dd81fa976a26b117a.

*** Reason for rollback ***

Fixforward, skipping tests on systems without JDK8

*** Original change description ***

Automated rollback of commit 7e48642db90977d37531053775be5ac9083078b7.

*** Reason for rollback ***

Breaks presubmit https://buildkite.com/bazel/google-bazel-presubmit/builds/42622#10f51cb9-f2c5-4b09-bd04-01196a37aba9

*** Original change description ***

Attach local JDK to JVM8_TOOLCHAIN_CONFIGURATION.

This is a partial revert of https://github.com/bazelbuild/bazel/commit/ec29e28a7f729c6a899ad0a75c770c4d174d78af.
The commit support rules_appengine usecase, which needs to supply additional parameters t...

***

PiperOrigin-RevId: 351129368
diff --git a/src/test/shell/bazel/bazel_java_test_defaults.sh b/src/test/shell/bazel/bazel_java_test_defaults.sh
index 9f88537..404f422 100755
--- a/src/test/shell/bazel/bazel_java_test_defaults.sh
+++ b/src/test/shell/bazel/bazel_java_test_defaults.sh
@@ -222,12 +222,11 @@
 default_java_toolchain(
   name = "jvm8_toolchain",
   configuration = JVM8_TOOLCHAIN_CONFIGURATION,
-  java_runtime = "@local_jdk//:jdk",
 )
 EOF
 
   bazel query //:jvm8_toolchain || fail "default_java_toolchain target failed to build"
-  bazel cquery 'deps(//:jvm8_toolchain)' >& $TEST_log || fail "failed to query //:jvm8_toolchain"
+  bazel query 'deps(//:jvm8_toolchain)' >& $TEST_log || fail "failed to query //:jvm8_toolchain"
 
   expect_log ":JavaBuilder"
   expect_log ":javac_jar"
diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index 0faec24..7fbaf36 100644
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -467,3 +467,10 @@
     ),
     visibility = ["//visibility:public"],
 )
+
+java_runtime_version_alias(
+    name = "jdk_8",
+    runtime_version = "8",
+    selected_java_runtime = ":legacy_current_java_runtime",
+    visibility = ["//visibility:public"],
+)
diff --git a/tools/jdk/default_java_toolchain.bzl b/tools/jdk/default_java_toolchain.bzl
index 8fea880..17ede2b 100644
--- a/tools/jdk/default_java_toolchain.bzl
+++ b/tools/jdk/default_java_toolchain.bzl
@@ -15,7 +15,7 @@
 """Bazel rules for creating Java toolchains."""
 
 JDK8_JVM_OPTS = [
-    "-Xbootclasspath/p:$(location @bazel_tools//tools/jdk:javac_jar)",
+    "-Xbootclasspath/p:$(location @remote_java_tools//:javac_jar)",
 ]
 
 # JVM options, without patching java.compiler and jdk.compiler modules.
@@ -74,6 +74,7 @@
 JVM8_TOOLCHAIN_CONFIGURATION = dict(
     tools = ["@remote_java_tools//:javac_jar"],
     jvm_opts = ["-Xbootclasspath/p:$(location @remote_java_tools//:javac_jar)"],
+    java_runtime = "@bazel_tools//tools/jdk:jdk_8",
 )
 
 DEFAULT_TOOLCHAIN_CONFIGURATION = dict(