Restructure rules_java

BEGIN_PUBLIC
Restructure rules_java

Design doc: https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit

END_PUBLIC

PiperOrigin-RevId: 605273963
Change-Id: Icca750162ebede5ad06e4f417fc2c5cb590617c5
diff --git a/java/BUILD b/java/BUILD
index dec049e..cd71ea9 100644
--- a/java/BUILD
+++ b/java/BUILD
@@ -7,15 +7,25 @@
 filegroup(
     name = "srcs",
     srcs = glob(["**"]) + [
+        "//java/modules:srcs",
         "//java/private:srcs",
         "//java/proto:srcs",
+        "//java/toolchains:srcs",
     ],
     visibility = ["//:__pkg__"],
 )
 
 bzl_library(
     name = "rules",
-    srcs = ["defs.bzl"],
+    srcs = [
+        "defs.bzl",
+        "java_binary.bzl",
+        "java_import.bzl",
+        "java_library.bzl",
+        "java_plugin.bzl",
+        "java_single_jar.bzl",
+        "java_test.bzl",
+    ],
     visibility = ["//visibility:public"],
     deps = ["//java/private"],
 )
diff --git a/java/defs.bzl b/java/defs.bzl
index 31cd01d..51a235b 100644
--- a/java/defs.bzl
+++ b/java/defs.bzl
@@ -13,142 +13,43 @@
 # limitations under the License.
 """Starlark rules for building Java projects."""
 
-load("//java/private:native.bzl", "NativeJavaInfo", "NativeJavaPluginInfo", "native_java_common")
+load("//java:java_binary.bzl", _java_binary = "java_binary")
+load("//java:java_import.bzl", _java_import = "java_import")
+load("//java:java_library.bzl", _java_library = "java_library")
+load("//java:java_plugin.bzl", _java_plugin = "java_plugin")
+load("//java:java_test.bzl", _java_test = "java_test")
+load("//java/modules:java_common.bzl", _java_common = "java_common")
+load("//java/modules:java_info.bzl", _JavaInfo = "JavaInfo")
+load("//java/modules:java_plugin_info.bzl", _JavaPluginInfo = "JavaPluginInfo")
+load("//java/proto:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library")
+load("//java/proto:java_proto_library.bzl", _java_proto_library = "java_proto_library")
+load("//java/toolchains:java_package_configuration.bzl", _java_package_configuration = "java_package_configuration")
+load("//java/toolchains:java_runtime.bzl", _java_runtime = "java_runtime")
+load("//java/toolchains:java_toolchain.bzl", _java_toolchain = "java_toolchain")
 
-# Do not touch: This line marks the end of loads; needed for PR importing.
-
-_MIGRATION_TAG = "__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
 version = "7.4.0"
 
-def _add_tags(attrs):
-    if "tags" in attrs and attrs["tags"] != None:
-        attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
-    else:
-        attrs["tags"] = [_MIGRATION_TAG]
-    return attrs
+# Language rules
 
-def java_binary(**attrs):
-    """Bazel java_binary rule.
+java_binary = _java_binary
+java_test = _java_test
+java_library = _java_library
+java_plugin = _java_plugin
+java_import = _java_import
 
-    https://docs.bazel.build/versions/master/be/java.html#java_binary
+# Toolchain rules
 
-    Args:
-      **attrs: Rule attributes
-    """
+java_runtime = _java_runtime
+java_toolchain = _java_toolchain
+java_package_configuration = _java_package_configuration
 
-    # buildifier: disable=native-java
-    native.java_binary(**_add_tags(attrs))
+# Proto rules
 
-def java_import(**attrs):
-    """Bazel java_import rule.
+java_proto_library = _java_proto_library
+java_lite_proto_library = _java_lite_proto_library
 
-    https://docs.bazel.build/versions/master/be/java.html#java_import
+# Modules and providers
 
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_import(**_add_tags(attrs))
-
-def java_library(**attrs):
-    """Bazel java_library rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_library
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_library(**_add_tags(attrs))
-
-def java_lite_proto_library(**attrs):
-    """Bazel java_lite_proto_library rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_lite_proto_library
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_lite_proto_library(**_add_tags(attrs))
-
-def java_proto_library(**attrs):
-    """Bazel java_proto_library rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_proto_library
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_proto_library(**_add_tags(attrs))
-
-def java_test(**attrs):
-    """Bazel java_test rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_test
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_test(**_add_tags(attrs))
-
-def java_package_configuration(**attrs):
-    """Bazel java_package_configuration rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_package_configuration
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_package_configuration(**_add_tags(attrs))
-
-def java_plugin(**attrs):
-    """Bazel java_plugin rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_plugin
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_plugin(**_add_tags(attrs))
-
-def java_runtime(**attrs):
-    """Bazel java_runtime rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_runtime
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_runtime(**_add_tags(attrs))
-
-def java_toolchain(**attrs):
-    """Bazel java_toolchain rule.
-
-    https://docs.bazel.build/versions/master/be/java.html#java_toolchain
-
-    Args:
-      **attrs: Rule attributes
-    """
-
-    # buildifier: disable=native-java
-    native.java_toolchain(**_add_tags(attrs))
-
-java_common = native_java_common
-
-JavaInfo = NativeJavaInfo
-
-JavaPluginInfo = NativeJavaPluginInfo
+JavaInfo = _JavaInfo
+JavaPluginInfo = _JavaPluginInfo
+java_common = _java_common
diff --git a/java/java_binary.bzl b/java/java_binary.bzl
new file mode 100644
index 0000000..18f5b86
--- /dev/null
+++ b/java/java_binary.bzl
@@ -0,0 +1,30 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_binary rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+# Do not touch: This line marks the end of loads; needed for PR importing.
+
+def java_binary(**attrs):
+    """Bazel java_binary rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_binary
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_binary(**add_tags(attrs))
diff --git a/java/java_import.bzl b/java/java_import.bzl
new file mode 100644
index 0000000..dd23653
--- /dev/null
+++ b/java/java_import.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_import rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_import(**attrs):
+    """Bazel java_import rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_import
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_import(**add_tags(attrs))
diff --git a/java/java_library.bzl b/java/java_library.bzl
new file mode 100644
index 0000000..3bc0a53
--- /dev/null
+++ b/java/java_library.bzl
@@ -0,0 +1,30 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_library rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+# Do not touch: This line marks the end of loads; needed for PR importing.
+
+def java_library(**attrs):
+    """Bazel java_library rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_library
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_library(**add_tags(attrs))
diff --git a/java/java_plugin.bzl b/java/java_plugin.bzl
new file mode 100644
index 0000000..a95fc44
--- /dev/null
+++ b/java/java_plugin.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_plugin rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_plugin(**attrs):
+    """Bazel java_plugin rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_plugin
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_plugin(**add_tags(attrs))
diff --git a/java/java_test.bzl b/java/java_test.bzl
new file mode 100644
index 0000000..76a63a1
--- /dev/null
+++ b/java/java_test.bzl
@@ -0,0 +1,30 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_test rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+# Do not touch: This line marks the end of loads; needed for PR importing.
+
+def java_test(**attrs):
+    """Bazel java_test rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_test
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_test(**add_tags(attrs))
diff --git a/java/modules/BUILD b/java/modules/BUILD
new file mode 100644
index 0000000..d9ed6e6
--- /dev/null
+++ b/java/modules/BUILD
@@ -0,0 +1,18 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+filegroup(
+    name = "srcs",
+    srcs = glob(["**"]),
+    visibility = ["//java:__pkg__"],
+)
+
+bzl_library(
+    name = "modules",
+    srcs = glob(["*.bzl"]),
+    visibility = ["//visibility:public"],
+    deps = ["//java/private"],
+)
diff --git a/java/modules/java_common.bzl b/java/modules/java_common.bzl
new file mode 100644
index 0000000..201beba
--- /dev/null
+++ b/java/modules/java_common.bzl
@@ -0,0 +1,18 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_common module"""
+
+load("//java/private:native.bzl", "native_java_common")
+
+java_common = native_java_common
diff --git a/java/modules/java_info.bzl b/java/modules/java_info.bzl
new file mode 100644
index 0000000..e22fb3d
--- /dev/null
+++ b/java/modules/java_info.bzl
@@ -0,0 +1,18 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""JavaInfo provider"""
+
+load("//java/private:native.bzl", "NativeJavaInfo")
+
+JavaInfo = NativeJavaInfo
diff --git a/java/modules/java_plugin_info.bzl b/java/modules/java_plugin_info.bzl
new file mode 100644
index 0000000..36d84f9
--- /dev/null
+++ b/java/modules/java_plugin_info.bzl
@@ -0,0 +1,18 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""JavaPluginInfo provider"""
+
+load("//java/private:native.bzl", "NativeJavaPluginInfo")
+
+JavaPluginInfo = NativeJavaPluginInfo
diff --git a/java/private/BUILD b/java/private/BUILD
index 9f50995..bfd41c2 100644
--- a/java/private/BUILD
+++ b/java/private/BUILD
@@ -5,7 +5,7 @@
 bzl_library(
     name = "private",
     srcs = ["native.bzl"],
-    visibility = ["//java:__pkg__"],
+    visibility = ["//java:__subpackages__"],
 )
 
 filegroup(
diff --git a/java/private/add_tags.bzl b/java/private/add_tags.bzl
new file mode 100644
index 0000000..6f2e35b
--- /dev/null
+++ b/java/private/add_tags.bzl
@@ -0,0 +1,23 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""add_tags migration helper"""
+
+_MIGRATION_TAG = "__JAVA_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
+
+def add_tags(attrs):
+    if "tags" in attrs and attrs["tags"] != None:
+        attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
+    else:
+        attrs["tags"] = [_MIGRATION_TAG]
+    return attrs
diff --git a/java/proto/BUILD b/java/proto/BUILD
index 209a5f5..5876189 100644
--- a/java/proto/BUILD
+++ b/java/proto/BUILD
@@ -1,3 +1,5 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
 package(default_visibility = ["//visibility:public"])
 
 # Toolchain type provided by proto_lang_toolchain rule and used by java_proto_library
@@ -6,6 +8,13 @@
 # Toolchain type provided by proto_lang_toolchain rule and used by java_lite_proto_library
 toolchain_type(name = "lite_toolchain_type")
 
+bzl_library(
+    name = "proto_rules",
+    srcs = glob(["*.bzl"]),
+    visibility = ["//visibility:public"],
+    deps = ["//java/private"],
+)
+
 filegroup(
     name = "srcs",
     srcs = glob(["**"]),
diff --git a/java/proto/java_lite_proto_library.bzl b/java/proto/java_lite_proto_library.bzl
new file mode 100644
index 0000000..c800237
--- /dev/null
+++ b/java/proto/java_lite_proto_library.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_lite_proto_library rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_lite_proto_library(**attrs):
+    """Bazel java_lite_proto_library rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_lite_proto_library
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_lite_proto_library(**add_tags(attrs))
diff --git a/java/proto/java_proto_library.bzl b/java/proto/java_proto_library.bzl
new file mode 100644
index 0000000..cb3d3f5
--- /dev/null
+++ b/java/proto/java_proto_library.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_proto_library rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_proto_library(**attrs):
+    """Bazel java_proto_library rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_proto_library
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_proto_library(**add_tags(attrs))
diff --git a/java/toolchains/BUILD b/java/toolchains/BUILD
new file mode 100644
index 0000000..0cc6644
--- /dev/null
+++ b/java/toolchains/BUILD
@@ -0,0 +1,18 @@
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+filegroup(
+    name = "srcs",
+    srcs = glob(["**"]),
+    visibility = ["//java:__pkg__"],
+)
+
+bzl_library(
+    name = "toolchain_rules",
+    srcs = glob(["*.bzl"]),
+    visibility = ["//visibility:public"],
+    deps = ["//java/private"],
+)
diff --git a/java/toolchains/java_package_configuration.bzl b/java/toolchains/java_package_configuration.bzl
new file mode 100644
index 0000000..b68b5fc
--- /dev/null
+++ b/java/toolchains/java_package_configuration.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_package_configuration rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_package_configuration(**attrs):
+    """Bazel java_package_configuration rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_package_configuration
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_package_configuration(**add_tags(attrs))
diff --git a/java/toolchains/java_runtime.bzl b/java/toolchains/java_runtime.bzl
new file mode 100644
index 0000000..0f2eb8b
--- /dev/null
+++ b/java/toolchains/java_runtime.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_runtime rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_runtime(**attrs):
+    """Bazel java_runtime rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_runtime
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_runtime(**add_tags(attrs))
diff --git a/java/toolchains/java_toolchain.bzl b/java/toolchains/java_toolchain.bzl
new file mode 100644
index 0000000..a5f1cda
--- /dev/null
+++ b/java/toolchains/java_toolchain.bzl
@@ -0,0 +1,28 @@
+# Copyright 2023 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""java_toolchain rule"""
+
+load("//java/private:add_tags.bzl", "add_tags")
+
+def java_toolchain(**attrs):
+    """Bazel java_toolchain rule.
+
+    https://docs.bazel.build/versions/master/be/java.html#java_toolchain
+
+    Args:
+      **attrs: Rule attributes
+    """
+
+    # buildifier: disable=native-java
+    native.java_toolchain(**add_tags(attrs))