Use `target_compatible_with` for Java runtimes

The JDK is a runtime. Actions like `java_binary` output an executable that
contains a JDK in its runfiles, and that JDK needs to be compatible with the
target platform. (Actions like `genrule` that execute the JDK can depend
on the JDK as a `tool`, which does an explicit transition to the `exec`
platform.)

PiperOrigin-RevId: 426995073
Change-Id: I97ab530c56047b780b1a2170937ddf162660840b
diff --git a/java/repositories.bzl b/java/repositories.bzl
index 07f7e0e..eba6a7a 100644
--- a/java/repositories.bzl
+++ b/java/repositories.bzl
@@ -85,7 +85,7 @@
     maybe(
         remote_java_repository,
         name = "remote_jdk8_linux_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:aarch64",
         ],
@@ -100,7 +100,7 @@
     maybe(
         remote_java_repository,
         name = "remote_jdk8_linux",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],
@@ -115,7 +115,7 @@
     maybe(
         remote_java_repository,
         name = "remote_jdk8_macos",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -130,7 +130,7 @@
     maybe(
         remote_java_repository,
         name = "remote_jdk8_windows",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
@@ -156,7 +156,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_linux",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],
@@ -171,7 +171,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_linux_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:aarch64",
         ],
@@ -186,7 +186,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_linux_ppc64le",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:ppc",
         ],
@@ -202,7 +202,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_linux_s390x",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:s390x",
         ],
@@ -218,7 +218,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_macos",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -233,7 +233,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_macos_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:aarch64",
         ],
@@ -249,7 +249,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk11_win",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
@@ -266,7 +266,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk15_linux",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],
@@ -282,7 +282,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk15_macos",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -298,7 +298,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk15_macos_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:aarch64",
         ],
@@ -314,7 +314,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk15_win",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
@@ -332,7 +332,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk16_linux",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],
@@ -348,7 +348,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk16_macos",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -364,7 +364,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk16_macos_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:aarch64",
         ],
@@ -380,7 +380,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk16_win",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
@@ -398,7 +398,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk17_linux",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:linux",
             "@platforms//cpu:x86_64",
         ],
@@ -414,7 +414,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk17_macos",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:x86_64",
         ],
@@ -430,7 +430,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk17_macos_aarch64",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:macos",
             "@platforms//cpu:aarch64",
         ],
@@ -446,7 +446,7 @@
     maybe(
         remote_java_repository,
         name = "remotejdk17_win",
-        exec_compatible_with = [
+        target_compatible_with = [
             "@platforms//os:windows",
             "@platforms//cpu:x86_64",
         ],
diff --git a/toolchains/remote_java_repository.bzl b/toolchains/remote_java_repository.bzl
index 33c0d6e..31b93b8 100644
--- a/toolchains/remote_java_repository.bzl
+++ b/toolchains/remote_java_repository.bzl
@@ -31,17 +31,17 @@
     },
 )
 
-def remote_java_repository(name, version, exec_compatible_with, prefix = "remotejdk", **kwargs):
+def remote_java_repository(name, version, target_compatible_with = None, prefix = "remotejdk", **kwargs):
     """Imports and registers a JDK from a http archive.
 
-    Toolchain resolution is determined with exec_compatible_with
+    Toolchain resolution is determined with target_compatible_with
     parameter and constrained with --java_runtime_version flag either having value
     of "version" or "{prefix}_{version}" parameters.
 
     Args:
       name: A unique name for this rule.
       version: Version of the JDK imported.
-      exec_compatible_with: Platform constraints (CPU and OS) for this JDK.
+      target_compatible_with: Target platform constraints (CPU and OS) for this JDK.
       prefix: Optional alternative prefix for configuration flag value used to determine this JDK.
       **kwargs: Refer to http_archive documentation
     """
@@ -73,7 +73,7 @@
 )
 toolchain(
     name = "toolchain",
-    exec_compatible_with = {exec_compatible_with},
+    target_compatible_with = {target_compatible_with},
     target_settings = [":version_or_prefix_version_setting"],
     toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
     toolchain = "{toolchain}",
@@ -81,7 +81,7 @@
 """.format(
             prefix = prefix,
             version = version,
-            exec_compatible_with = exec_compatible_with,
+            target_compatible_with = target_compatible_with,
             toolchain = "@{repo}//:jdk".format(repo = name),
         ),
     )