Align dependency handling with Bazel best practices (#9165)

This commit removes the use of bind() since that function goes against
Bazel best practices:
https://docs.bazel.build/versions/main/external.html#repository-rules-1
The bind() function basically maps a dependency into //external, but
there is no good reason to do this. By mapping dependencies into
//external and relying on this in our own BUILD files, we're forcing
projects that depend on us to do the same. The one bind() call that I
did leave in place was //:python_headers. This one seems to be doing
something complicated I don't fully understand, and I don't want to risk
breaking it.

This change also moves our list of required Maven artifacts into a
constant in protobuf_deps.bzl. This way, projects that depend on us can
refer to this list when they invoke maven_install() and automatically
pull in all the necesary dependencies.

This fixes #9132.
diff --git a/java/core/BUILD b/java/core/BUILD
index c65f10a..1a37b4e 100644
--- a/java/core/BUILD
+++ b/java/core/BUILD
@@ -1,5 +1,5 @@
 load("@bazel_skylib//rules:build_test.bzl", "build_test")
-load("@rules_java//java:defs.bzl", "java_library", "java_proto_library", "java_lite_proto_library")
+load("@rules_java//java:defs.bzl", "java_library", "java_lite_proto_library", "java_proto_library")
 load("@rules_jvm_external//:defs.bzl", "java_export")
 load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
 load("//:internal.bzl", "conformance_test")
@@ -103,7 +103,7 @@
 java_library(
     name = "lite",
     srcs = LITE_SRCS + [
-        "//:gen_well_known_protos_javalite"
+        "//:gen_well_known_protos_javalite",
     ],
     visibility = [
         "//java/lite:__pkg__",
@@ -115,10 +115,10 @@
     name = "lite_mvn",
     maven_coordinates = "com.google.protobuf:protobuf-javalite:%s" % PROTOBUF_VERSION,
     pom_template = "//java/lite:pom_template.xml",
-    runtime_deps = [":lite"],
     resources = [
         "//:lite_well_known_protos",
     ],
+    runtime_deps = [":lite"],
 )
 
 java_library(
@@ -150,25 +150,25 @@
     name = "core_mvn",
     maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_VERSION,
     pom_template = "pom_template.xml",
-    runtime_deps = [":core"],
     resources = [
         "//:well_known_protos",
     ],
+    runtime_deps = [":core"],
 )
 
 filegroup(
     name = "release",
-    visibility = ["//java:__pkg__"],
     srcs = [
-        ":core_mvn-pom",
-        ":core_mvn-maven-source",
         ":core_mvn-docs",
+        ":core_mvn-maven-source",
+        ":core_mvn-pom",
         ":core_mvn-project",
-        ":lite_mvn-pom",
-        ":lite_mvn-maven-source",
         ":lite_mvn-docs",
+        ":lite_mvn-maven-source",
+        ":lite_mvn-pom",
         ":lite_mvn-project",
-    ]
+    ],
+    visibility = ["//java:__pkg__"],
 )
 
 proto_lang_toolchain(
@@ -207,22 +207,22 @@
     name = "test_util",
     srcs = [
         "src/test/java/com/google/protobuf/TestUtil.java",
-        "src/test/java/com/google/protobuf/TestUtilLite.java"
+        "src/test/java/com/google/protobuf/TestUtilLite.java",
     ],
     deps = [
         ":core",
         ":generic_test_protos_java_proto",
         ":java_test_protos_java_proto",
-        "//external:guava",
-        "//external:junit",
+        "@maven//:com_google_guava_guava",
+        "@maven//:junit_junit",
     ],
 )
 
 test_suite(
     name = "tests",
     tests = [
-        "core_build_test",
         "conformance_test",
+        "core_build_test",
         "core_tests",
     ],
 )
@@ -236,29 +236,32 @@
 
 conformance_test(
     name = "conformance_test",
-    testee = "//:conformance_java",
     failure_list = "//:conformance/failure_list_java.txt",
+    testee = "//:conformance_java",
     text_format_failure_list = "//:conformance/text_format_failure_list_java.txt",
 )
 
 junit_tests(
     name = "core_tests",
-    srcs = glob(["src/test/java/**/*.java"], exclude = [
-        "src/test/java/com/google/protobuf/TestUtil.java",
-        "src/test/java/com/google/protobuf/TestUtilLite.java",
-    ]),
-    data = ["//:testdata"],
     size = "large",
+    srcs = glob(
+        ["src/test/java/**/*.java"],
+        exclude = [
+            "src/test/java/com/google/protobuf/TestUtil.java",
+            "src/test/java/com/google/protobuf/TestUtilLite.java",
+        ],
+    ),
+    data = ["//:testdata"],
     deps = [
         ":core",
         ":generic_test_protos_java_proto",
         ":java_test_protos_java_proto",
         ":test_util",
-        "//external:easymock",
-        "//external:guava",
-        "//external:junit",
-        "//external:truth",
-    ]
+        "@maven//:com_google_guava_guava",
+        "@maven//:com_google_truth_truth",
+        "@maven//:junit_junit",
+        "@maven//:org_easymock_easymock",
+    ],
 )
 
 java_lite_proto_library(
@@ -281,17 +284,17 @@
     name = "rewrite_javalite_test_util",
     srcs = [
         "//java/lite:lite.awk",
-        "src/test/java/com/google/protobuf/TestUtil.java"
+        "src/test/java/com/google/protobuf/TestUtil.java",
     ],
     outs = ["TestUtil.java"],
-    cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@"
+    cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@",
 )
 
 java_library(
     name = "test_util_lite",
     srcs = [
+        "src/test/java/com/google/protobuf/TestUtilLite.java",
         ":rewrite_javalite_test_util",
-        "src/test/java/com/google/protobuf/TestUtilLite.java"
     ],
     visibility = [
         "//java/lite:__pkg__",
@@ -300,8 +303,8 @@
         ":generic_test_protos_java_proto_lite",
         ":java_test_protos_java_proto_lite",
         ":lite_runtime_only",
-        "//external:guava",
-        "//external:junit",
+        "@maven//:com_google_guava_guava",
+        "@maven//:junit_junit",
     ],
 )
 
@@ -350,18 +353,20 @@
 
 junit_tests(
     name = "lite_tests",
-    srcs = glob(["src/test/java/**/*.java"], exclude = LITE_TEST_EXCLUSIONS),
+    size = "large",
+    srcs = glob(
+        ["src/test/java/**/*.java"],
+        exclude = LITE_TEST_EXCLUSIONS,
+    ),
     data = ["//:testdata"],
     test_prefix = "Lite",
-    size = "large",
     deps = [
-        ":lite",
         ":generic_test_protos_java_proto_lite",
         ":java_test_protos_java_proto_lite",
+        ":lite",
         ":test_util_lite",
-        "//external:easymock",
-        "//external:junit",
-        "//external:truth",
-    ]
+        "@maven//:com_google_truth_truth",
+        "@maven//:junit_junit",
+        "@maven//:org_easymock_easymock",
+    ],
 )
-
diff --git a/java/lite/BUILD b/java/lite/BUILD
index 7089f95..17e9667 100644
--- a/java/lite/BUILD
+++ b/java/lite/BUILD
@@ -3,8 +3,15 @@
 load("//:internal.bzl", "conformance_test")
 load("//java/internal:testing.bzl", "junit_tests")
 
-exports_files(["lite.awk"], visibility = ["//java/core:__pkg__"])
-exports_files(["pom_template.xml"], visibility = ["//java/core:__pkg__"])
+exports_files(
+    ["lite.awk"],
+    visibility = ["//java/core:__pkg__"],
+)
+
+exports_files(
+    ["pom_template.xml"],
+    visibility = ["//java/core:__pkg__"],
+)
 
 alias(
     name = "lite",
@@ -22,8 +29,8 @@
 test_suite(
     name = "tests",
     tests = [
-        "lite_build_test",
         "conformance_test",
+        "lite_build_test",
         "lite_tests",
         "//java/core:lite_tests",
     ],
@@ -38,21 +45,21 @@
 
 conformance_test(
     name = "conformance_test",
-    testee = "//:conformance_java_lite",
     failure_list = "//:conformance/failure_list_java_lite.txt",
+    testee = "//:conformance_java_lite",
     text_format_failure_list = "//:conformance/text_format_failure_list_java_lite.txt",
 )
 
 junit_tests(
     name = "lite_tests",
-    srcs = glob(["src/test/**/*.java"]),
     size = "small",
+    srcs = glob(["src/test/**/*.java"]),
     deps = [
         ":lite",
-        "//external:junit",
-        "//external:truth",
         "//java/core:generic_test_protos_java_proto_lite",
         "//java/core:java_test_protos_java_proto_lite",
         "//java/core:test_util_lite",
+        "@maven//:com_google_truth_truth",
+        "@maven//:junit_junit",
     ],
 )
diff --git a/java/util/BUILD b/java/util/BUILD
index 3855da9..ee6ddea 100644
--- a/java/util/BUILD
+++ b/java/util/BUILD
@@ -11,33 +11,34 @@
     ]),
     visibility = ["//visibility:public"],
     deps = [
-        "//external:error_prone_annotations",
-        "//external:j2objc_annotations",
-        "//external:gson",
-        "//external:jsr305",
-        "//external:guava",
         "//java/core",
         "//java/lite",
+        "@maven//:com_google_code_findbugs_jsr305",
+        "@maven//:com_google_code_gson_gson",
+        "@maven//:com_google_errorprone_error_prone_annotations",
+        "@maven//:com_google_guava_guava",
+        "@maven//:com_google_j2objc_j2objc_annotations",
     ],
 )
+
 # Bazel users, don't depend on this target, use :util.
 java_export(
     name = "util_mvn",
     maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_VERSION,
     pom_template = "pom_template.xml",
-    runtime_deps = [":util"],
     visibility = ["//java:__pkg__"],
+    runtime_deps = [":util"],
 )
 
 filegroup(
     name = "release",
-    visibility = ["//java:__pkg__"],
     srcs = [
-        ":util_mvn-pom",
-        ":util_mvn-maven-source",
         ":util_mvn-docs",
+        ":util_mvn-maven-source",
+        ":util_mvn-pom",
         ":util_mvn-project",
-    ]
+    ],
+    visibility = ["//java:__pkg__"],
 )
 
 proto_library(
@@ -60,15 +61,15 @@
 
 junit_tests(
     name = "tests",
-    srcs = glob(["src/test/java/**/*.java"]),
     package_name = "com.google.protobuf.util",
+    srcs = glob(["src/test/java/**/*.java"]),
     deps = [
         ":test_protos_java_proto",
         ":util",
-        "//external:guava",
-        "//external:junit",
-        "//external:truth",
         "//java/core",
         "//java/core:generic_test_protos_java_proto",
+        "@maven//:com_google_guava_guava",
+        "@maven//:com_google_truth_truth",
+        "@maven//:junit_junit",
     ],
 )