bazel: Use the `artifact` macro for loading maven deps

The recommended way to load dependencies from `rules_jvm_external`
is to make use of the `@maven` workspace, and the most readable
way of doing that is to use the `artifact` macro provides.

This removes the need to generate the "compat" namespaces, which
`rules_jvm_external` provided for backwards compatibility with
older releases. This change also sets things up for supporting
`bzlmod`: this requires all workspaces accessed by a library to
be named "up front" in the `MODULE.bazel` file. This way, the
only repo that needs to be exported is `@maven`, rather than the
current huge list.
This commit is contained in:
David Burns 2024-03-28 21:33:32 +00:00 committed by GitHub
parent 4ef1baddd2
commit 00649913b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 169 additions and 139 deletions

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_jvm_external//:defs.bzl", "artifact")
load(":java_grpc_library.bzl", "java_grpc_library")
java_proto_library(
@ -33,9 +34,9 @@ java_library(
"//protobuf",
"//stub",
"//stub:javax_annotation",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)
@ -47,8 +48,8 @@ java_library(
"//protobuf-lite",
"//stub",
"//stub:javax_annotation",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)
@ -56,7 +57,7 @@ java_plugin(
name = "auto_value",
generates_api = 1,
processor_class = "com.google.auto.value.processor.AutoValueProcessor",
deps = ["@com_google_auto_value_auto_value//jar"],
deps = [artifact("com.google.auto.value:auto-value")],
)
java_library(
@ -65,7 +66,7 @@ java_library(
neverlink = 1,
visibility = ["//:__subpackages__"],
exports = [
"@com_google_auto_value_auto_value_annotations//jar",
"@org_apache_tomcat_annotations_api//jar", # @Generated for Java 9+
artifact("com.google.auto.value:auto-value-annotations"),
artifact("org.apache.tomcat:annotations-api"), # @Generated for Java 9+
],
)

View File

@ -34,14 +34,9 @@ switched_rules_by_language(
maven_install(
artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS + PROTOBUF_MAVEN_ARTIFACTS,
generate_compat_repositories = True,
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
repositories = [
"https://repo.maven.apache.org/maven2/",
],
strict_visibility = True,
)
load("@maven//:compat.bzl", "compat_repositories")
compat_repositories()

View File

@ -1,3 +1,4 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:java_grpc_library.bzl", "java_grpc_library")
@ -14,16 +15,16 @@ java_library(
"//grpclb",
"//netty",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@io_netty_netty_buffer//jar",
"@io_netty_netty_codec//jar",
"@io_netty_netty_common//jar",
"@io_netty_netty_handler//jar",
"@io_netty_netty_transport//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("io.netty:netty-buffer"),
artifact("io.netty:netty-codec"),
artifact("io.netty:netty-common"),
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-transport"),
],
)
@ -41,13 +42,13 @@ java_library(
"//auth",
"//core:internal",
"//netty",
"@com_google_auth_google_auth_library_oauth2_http//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@io_netty_netty_common//jar",
"@io_netty_netty_handler//jar",
"@io_netty_netty_transport//jar",
artifact("com.google.auth:google-auth-library-oauth2-http"),
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("io.netty:netty-common"),
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-transport"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "api",
srcs = glob([
@ -7,10 +9,10 @@ java_library(
javacopts = ["-Xep:DoNotCall:OFF"], # Remove once requiring Bazel 3.4.0+; allows non-final
visibility = ["//visibility:public"],
deps = [
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_failureaccess//jar", # future transitive dep of Guava. See #5214
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:failureaccess"), # future transitive dep of Guava. See #5214
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "auth",
srcs = glob([
@ -6,9 +8,9 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//api",
"@com_google_auth_google_auth_library_credentials//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
artifact("com.google.auth:google-auth-library-credentials"),
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "census",
srcs = glob([
@ -7,9 +9,9 @@ java_library(
deps = [
"//api",
"//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@io_opencensus_opencensus_api//jar",
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("io.opencensus:opencensus-api"),
artifact("io.opencensus:opencensus-contrib-grpc-metrics"),
],
)

View File

@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_rpc_toolchain")
# This should not generally be referenced. Users should use java_grpc_library
@ -22,8 +23,8 @@ java_library(
"//protobuf",
"//stub",
"//stub:javax_annotation",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
"@com_google_protobuf//:protobuf_java",
],
)
@ -35,8 +36,8 @@ java_library(
"//protobuf-lite",
"//stub",
"//stub:javax_annotation",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "core",
visibility = ["//visibility:public"],
@ -23,14 +25,14 @@ java_library(
deps = [
"//api",
"//context",
"@com_google_android_annotations//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_code_gson_gson//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@io_perfmark_perfmark_api//jar",
"@org_codehaus_mojo_animal_sniffer_annotations//jar",
artifact("com.google.code.gson:gson"),
artifact("com.google.android:annotations"),
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("io.perfmark:perfmark-api"),
artifact("org.codehaus.mojo:animal-sniffer-annotations"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "googleapis",
srcs = glob([
@ -9,6 +11,6 @@ java_library(
"//api",
"//core:internal",
"//xds",
"@com_google_guava_guava//jar",
artifact("com.google.guava:guava"),
],
)

View File

@ -1,3 +1,4 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")
java_library(
@ -16,11 +17,11 @@ java_library(
"//core:internal",
"//util",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_google_protobuf//:protobuf_java_util",
"@io_grpc_grpc_proto//:grpclb_load_balancer_java_proto",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "inprocess",
srcs = glob([
@ -5,12 +7,12 @@ java_library(
]),
visibility = ["//visibility:public"],
deps = [
"//core:internal",
"//api",
"//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"//core:internal",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "netty",
srcs = glob([
@ -10,22 +12,22 @@ java_library(
deps = [
"//api",
"//core:internal",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@io_netty_netty_buffer//jar",
"@io_netty_netty_codec//jar",
"@io_netty_netty_codec_http//jar",
"@io_netty_netty_codec_http2//jar",
"@io_netty_netty_codec_socks//jar",
"@io_netty_netty_common//jar",
"@io_netty_netty_handler//jar",
"@io_netty_netty_handler_proxy//jar",
"@io_netty_netty_resolver//jar",
"@io_netty_netty_transport//jar",
"@io_netty_netty_transport_native_unix_common//jar",
"@io_perfmark_perfmark_api//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("io.netty:netty-buffer"),
artifact("io.netty:netty-codec"),
artifact("io.netty:netty-codec-http"),
artifact("io.netty:netty-codec-http2"),
artifact("io.netty:netty-codec-socks"),
artifact("io.netty:netty-common"),
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-handler-proxy"),
artifact("io.netty:netty-resolver"),
artifact("io.netty:netty-transport"),
artifact("io.netty:netty-transport-native-unix-common"),
artifact("io.perfmark:perfmark-api"),
],
)

View File

@ -1,12 +1,14 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
# Publicly exposed in //netty package. Purposefully does not export any symbols.
java_library(
name = "shaded",
visibility = ["//netty:__pkg__"],
runtime_deps = [
"//netty",
"@io_netty_netty_tcnative_boringssl_static//jar",
"@io_netty_netty_tcnative_classes//jar",
"@io_netty_netty_transport_native_unix_common//jar",
"@io_netty_netty_transport_native_epoll_linux_x86_64//jar",
artifact("io.netty:netty-tcnative-boringssl-static"),
artifact("io.netty:netty-tcnative-classes"),
artifact("io.netty:netty-transport-native-unix-common"),
artifact("io.netty:netty-transport-native-epoll_linux_x86_64"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "okhttp",
srcs = glob([
@ -12,12 +14,12 @@ java_library(
"//api",
"//core:internal",
"//util",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_squareup_okhttp_okhttp//jar",
"@com_squareup_okio_okio//jar",
"@io_perfmark_perfmark_api//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("com.squareup.okhttp:okhttp"),
artifact("com.squareup.okio:okio"),
artifact("io.perfmark:perfmark-api"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "protobuf-lite",
srcs = glob([
@ -6,9 +8,9 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//api",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
] + select({
":android": ["@com_google_protobuf_javalite//:protobuf_javalite"],
"//conditions:default": ["@com_google_protobuf//:protobuf_java"],

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "protobuf",
srcs = glob([
@ -7,10 +9,10 @@ java_library(
deps = [
"//api",
"//protobuf-lite",
"@com_google_api_grpc_proto_google_common_protos//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_google_protobuf//:protobuf_java",
artifact("com.google.api.grpc:proto-google-common-protos"),
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)

View File

@ -1,3 +1,4 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")
java_library(
@ -12,13 +13,13 @@ java_library(
"//api",
"//core",
"//core:internal",
"//util",
"//stub",
"@com_google_auto_value_auto_value_annotations//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"//util",
"@io_grpc_grpc_proto//:rls_config_java_proto",
"@io_grpc_grpc_proto//:rls_java_proto",
artifact("com.google.auto.value:auto-value-annotations"),
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)

View File

@ -1,3 +1,4 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")
package(default_visibility = ["//visibility:public"])
@ -26,7 +27,7 @@ java_library(
deps = [
":channelz",
"//api",
"@com_google_code_findbugs_jsr305//jar",
artifact("com.google.code.findbugs:jsr305"),
],
)
@ -35,15 +36,15 @@ java_library(
srcs = [
"src/main/java/io/grpc/services/CallMetricRecorder.java",
"src/main/java/io/grpc/services/MetricRecorder.java",
"src/main/java/io/grpc/services/MetricReport.java",
"src/main/java/io/grpc/services/MetricRecorderHelper.java",
"src/main/java/io/grpc/services/MetricReport.java",
],
deps = [
"//api",
"//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
],
)
@ -72,11 +73,11 @@ java_library(
":_channelz_java_grpc",
"//api",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@io_grpc_grpc_proto//:channelz_java_proto",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)
@ -90,11 +91,11 @@ java_library(
"//api",
"//protobuf",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@io_grpc_grpc_proto//:reflection_java_proto_deprecated",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)
@ -110,9 +111,9 @@ java_library(
"//api",
"//context",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@io_grpc_grpc_proto//:health_java_proto",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)
@ -131,9 +132,9 @@ java_library(
"//api",
"//core:internal",
"//util",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@io_grpc_grpc_proto//:health_java_proto",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "stub",
srcs = glob([
@ -7,10 +9,10 @@ java_library(
deps = [
"//api",
"//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
],
)
@ -20,5 +22,5 @@ java_library(
name = "javax_annotation",
neverlink = 1, # @Generated is source-retention
visibility = ["//visibility:public"],
exports = ["@org_apache_tomcat_annotations_api//jar"],
exports = [artifact("org.apache.tomcat:annotations-api")],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "testing",
testonly = 1,
@ -12,12 +14,12 @@ java_library(
"//api",
"//context",
"//inprocess",
"//util",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@com_google_truth_truth//jar",
"@junit_junit//jar",
"//util",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("com.google.truth:truth"),
artifact("junit:junit"),
],
)

View File

@ -1,3 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
java_library(
name = "util",
srcs = glob([
@ -10,9 +12,9 @@ java_library(
deps = [
"//api",
"//core:internal",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar",
"@org_codehaus_mojo_animal_sniffer_annotations//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
artifact("org.codehaus.mojo:animal-sniffer-annotations"),
],
)

View File

@ -1,3 +1,4 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:java_grpc_library.bzl", "java_grpc_library")
# Mirrors the dependencies included in the artifact on Maven Central for usage
@ -43,19 +44,19 @@ java_library(
"//stub",
"//services:metrics",
"//services:metrics_internal",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_code_gson_gson//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_googleapis//google/rpc:rpc_java_proto",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@com_google_re2j_re2j//jar",
"@io_netty_netty_buffer//jar",
"@io_netty_netty_codec//jar",
"@io_netty_netty_common//jar",
"@io_netty_netty_handler//jar",
"@io_netty_netty_transport//jar",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.code.gson:gson"),
artifact("com.google.errorprone:error_prone_annotations"),
artifact("com.google.guava:guava"),
artifact("com.google.re2j:re2j"),
artifact("io.netty:netty-buffer"),
artifact("io.netty:netty-codec"),
artifact("io.netty:netty-common"),
artifact("io.netty:netty-handler"),
artifact("io.netty:netty-transport"),
],
)
@ -150,9 +151,9 @@ java_library(
"//services:metrics",
"//services:metrics_internal",
"//stub",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java_util",
artifact("com.google.code.findbugs:jsr305"),
artifact("com.google.guava:guava"),
],
)