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",
+ ],
)
-