1# Copyright 2019 Google LLC 2# 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions are 5# met: 6# 7# * Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above 10# copyright notice, this list of conditions and the following disclaimer 11# in the documentation and/or other materials provided with the 12# distribution. 13# * Neither the name of Google LLC nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 30load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") 31load("@com_google_api_gax_java_properties//:dependencies.properties.bzl", "PROPERTIES") 32 33def com_google_api_gax_java_repositories(): 34 # Import dependencies shared between Gradle and Bazel (i.e. maven dependencies) 35 for name, artifact in PROPERTIES.items(): 36 _maybe( 37 jvm_maven_import_external, 38 name = name, 39 strip_repo_prefix = "maven.", 40 artifact = _fix_bazel_artifact_format(artifact), 41 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 42 licenses = ["notice", "reciprocal"], 43 ) 44 45 # Import Bazel-only dependencies (Gradle version will import maven artifacts of same 46 # version, while Bazel will depend on Bazel workspaces). The versions are shared in the 47 # properties file. 48 49 _protobuf_version = PROPERTIES["version.com_google_protobuf"] 50 _protobuf_version_in_link = "v%s" % _protobuf_version 51 _maybe( 52 http_archive, 53 name = "com_google_protobuf", 54 urls = ["https://github.com/protocolbuffers/protobuf/archive/%s.zip" % _protobuf_version_in_link], 55 strip_prefix = "protobuf-%s" % _protobuf_version, 56 ) 57 58 _grpc_version = PROPERTIES["version.io_grpc"] 59 _grpc_version_in_link = "v%s" % _grpc_version 60 _maybe( 61 http_archive, 62 name = "io_grpc_grpc_java", 63 urls = ["https://github.com/grpc/grpc-java/archive/%s.zip" % _grpc_version_in_link], 64 strip_prefix = "grpc-java-%s" % _grpc_version, 65 ) 66 67 _bazel_skylib_version = "1.0.3" 68 _maybe( 69 http_archive, 70 name = "bazel_skylib", 71 strip_prefix = "bazel-skylib-%s" % _bazel_skylib_version, 72 urls = ["https://github.com/bazelbuild/bazel-skylib/archive/%s.zip" % _bazel_skylib_version], 73 ) 74 75 _maybe( 76 jvm_maven_import_external, 77 name = "com_google_protobuf_java_util", 78 artifact = "com.google.protobuf:protobuf-java-util:%s" % PROPERTIES["version.com_google_protobuf"], 79 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 80 licenses = ["notice", "reciprocal"], 81 ) 82 83 _maybe( 84 jvm_maven_import_external, 85 name = "com_google_protobuf_java", 86 artifact = "com.google.protobuf:protobuf-java:%s" % PROPERTIES["version.com_google_protobuf"], 87 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 88 licenses = ["notice", "reciprocal"], 89 ) 90 91 _maybe( 92 jvm_maven_import_external, 93 name = "io_grpc_grpc_netty_shaded", 94 artifact = "io.grpc:grpc-netty-shaded:%s" % PROPERTIES["version.io_grpc"], 95 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 96 licenses = ["notice", "reciprocal"], 97 ) 98 99 _maybe( 100 jvm_maven_import_external, 101 name = "io_grpc_grpc_grpclb", 102 artifact = "io.grpc:grpc-grpclb:%s" % PROPERTIES["version.io_grpc"], 103 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 104 licenses = ["notice", "reciprocal"], 105 ) 106 107 _maybe( 108 jvm_maven_import_external, 109 name = "google_java_format_all_deps", 110 artifact = "com.google.googlejavaformat:google-java-format:jar:all-deps:%s" % PROPERTIES["version.google_java_format"], 111 server_urls = ["https://repo.maven.apache.org/maven2/", "http://repo1.maven.org/maven2/"], 112 licenses = ["notice", "reciprocal"], 113 ) 114 115 _maybe( 116 native.bind, 117 name = "guava", 118 actual = "@com_google_guava_guava//jar", 119 ) 120 121 _maybe( 122 native.bind, 123 name = "gson", 124 actual = "@com_google_code_gson_gson//jar", 125 ) 126 127 _maybe( 128 native.bind, 129 name = "error_prone_annotations", 130 actual = "@com_google_errorprone_error_prone_annotations//jar", 131 ) 132 133def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs): 134 if not name.startswith(strip_repo_prefix): 135 return 136 repo_name = name[len(strip_repo_prefix):] 137 if repo_name in native.existing_rules(): 138 return 139 repo_rule(name = repo_name, **kwargs) 140 141def _fix_bazel_artifact_format(artifact_id): 142 # Fix the artifact id format discrepancy between Bazel & Gradle. 143 # This is relevant only when classifier is specified explicitly. 144 # Bazel format: groupId:artifactId:jar:classifier:version 145 # Gradle format: groupId:artifactId:version:classifier 146 ids = artifact_id.split(":") 147 if len(ids) != 4: 148 return artifact_id 149 return "%s:%s:%s:%s:%s" % (ids[0], ids[1], "jar", ids[3], ids[2]) 150