From a1b3e2aa026aca4c6bc936e120bfe4ab2ea2dfe8 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 13 Jul 2023 10:02:45 +0100 Subject: [PATCH] fix: Reflect protobuf updates into MODULE.bazel (#185) --- MODULE.bazel | 14 ++++++++++++-- java/private/non-module-deps.bzl | 9 ++------- repositories.bzl | 19 +++++++++++-------- third_party/protobuf_version.bzl | 2 ++ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index d42c26e2..05789731 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,16 +4,22 @@ module( repo_name = "contrib_rules_jvm", ) +# TODO: This should be read from repositories.bzl, but we can't until this issue is solved: +# - https://github.com/bazelbuild/bazel/issues/17880 +PROTOBUF_VERSION = "21.7" +# The java packages are published to maven under a different versioning scheme. +PROTOBUF_JAVA_VERSION = "3.{}".format(PROTOBUF_VERSION) + bazel_dep(name = "apple_rules_lint", version = "0.3.2") bazel_dep(name = "bazel_skylib", version = "1.4.2") bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.2") bazel_dep(name = "gazelle", version = "0.31.1", repo_name = "bazel_gazelle") -bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf") +bazel_dep(name = "protobuf", version = PROTOBUF_VERSION, repo_name = "com_google_protobuf") bazel_dep(name = "rules_cc", version = "0.0.6") bazel_dep(name = "rules_go", version = "0.40.1", repo_name = "io_bazel_rules_go") bazel_dep(name = "rules_java", version = "6.1.1") bazel_dep(name = "rules_jvm_external", version = "5.3") -bazel_dep(name = "rules_proto", version = "5.3.0-21.7") +bazel_dep(name = "rules_proto", version = "5.3.0-{}".format(PROTOBUF_VERSION)) bazel_dep(name = "stardoc", version = "0.5.6", repo_name = "io_bazel_stardoc") non_module_deps = use_extension("//java/private:non-module-deps.bzl", "non_module_deps") @@ -119,6 +125,10 @@ maven.install( # Spotbugs deps "org.slf4j:slf4j-api:1.7.32", "org.slf4j:slf4j-jdk14:1.7.32", + + # We explicitly declare a protobuf runtime version + # so that it coincides with the one we use to generate the code. + "com.google.protobuf:protobuf-java:{}".format(PROTOBUF_JAVA_VERSION), ] + IO_GRPC_GRPC_JAVA_ARTIFACTS, fail_if_repin_required = True, generate_compat_repositories = True, diff --git a/java/private/non-module-deps.bzl b/java/private/non-module-deps.bzl index 3fff612a..a0dc76b5 100644 --- a/java/private/non-module-deps.bzl +++ b/java/private/non-module-deps.bzl @@ -1,14 +1,9 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//:repositories.bzl", "io_grpc_grpc_java") def _non_module_dependencies_impl(mctx): - maybe( - http_archive, - name = "io_grpc_grpc_java", - sha256 = "b6cfc524647cc680e66989ab22a10b66dc5de8c6d8499f91a7e633634c594c61", - strip_prefix = "grpc-java-1.51.1", - urls = ["https://github.com/grpc/grpc-java/archive/v1.51.1.tar.gz"], - ) + io_grpc_grpc_java() non_module_deps = module_extension( implementation = _non_module_dependencies_impl, diff --git a/repositories.bzl b/repositories.bzl index 0c0073b8..982b19cc 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -55,6 +55,8 @@ def contrib_rules_jvm_deps(): ) def contrib_rules_jvm_gazelle_deps(): + io_grpc_grpc_java() + maybe( http_archive, name = "bazel_gazelle", @@ -79,14 +81,6 @@ def contrib_rules_jvm_gazelle_deps(): url = "https://github.com/bazelbuild/rules_go/releases/download/v0.40.1/rules_go-v0.40.1.zip", ) - maybe( - http_archive, - name = "io_grpc_grpc_java", - sha256 = "17dd91014032a147c978ae99582fddd950f5444388eae700cf51eda0326ad2f9", - strip_prefix = "grpc-java-1.56.1", - urls = ["https://github.com/grpc/grpc-java/archive/v1.56.1.tar.gz"], - ) - maybe( http_archive, name = "rules_proto", @@ -96,3 +90,12 @@ def contrib_rules_jvm_gazelle_deps(): strip_prefix = "rules_proto-5.3.0-{}".format(PROTOBUF_VERSION), url = "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-{}.tar.gz".format(PROTOBUF_VERSION), ) + +def io_grpc_grpc_java(): + maybe( + http_archive, + name = "io_grpc_grpc_java", + sha256 = "17dd91014032a147c978ae99582fddd950f5444388eae700cf51eda0326ad2f9", + strip_prefix = "grpc-java-1.56.1", + urls = ["https://github.com/grpc/grpc-java/archive/v1.56.1.tar.gz"], + ) diff --git a/third_party/protobuf_version.bzl b/third_party/protobuf_version.bzl index 478102d8..2efca350 100644 --- a/third_party/protobuf_version.bzl +++ b/third_party/protobuf_version.bzl @@ -1,3 +1,5 @@ +# Please keep in sync with MODULE.bazel until +# https://github.com/bazelbuild/bazel/issues/17880 is solved. PROTOBUF_VERSION = "21.7" # The java packages are published to maven under a different versioning scheme.