diff --git a/coursier.bzl b/coursier.bzl index e926b1012..d3fc8528e 100644 --- a/coursier.bzl +++ b/coursier.bzl @@ -15,7 +15,7 @@ load("//third_party/bazel_json/lib:json_parser.bzl", _json_parse = "json_parse") load("//private/rules:jetifier.bzl", "jetify_artifact_dependencies", "jetify_maven_coord") load("//:specs.bzl", "maven", "parse", "utils") load("//private:artifact_utilities.bzl", "deduplicate_and_sort_artifacts") -load("//private:coursier_utilities.bzl", "SUPPORTED_PACKAGING_TYPES", "escape") +load("//private:coursier_utilities.bzl", "SUPPORTED_PACKAGING_TYPES", "escape", "strip_packaging_and_classifier") load("//private:dependency_tree_parser.bzl", "JETIFY_INCLUDE_LIST_JETIFY_ALL", "parser") load("//private:java_utilities.bzl", "parse_java_version") load("//private:proxy.bzl", "get_java_proxy_args") @@ -471,11 +471,13 @@ def _pinned_coursier_fetch_impl(repository_ctx): "load(\"@bazel_tools//tools/build_defs/repo:utils.bzl\", \"maybe\")", "def pinned_maven_install():", ] + maven_artifacts = [] netrc_entries = {} for artifact in dep_tree["dependencies"]: if artifact.get("url") != None: http_file_repository_name = escape(artifact["coord"]) + maven_artifacts.extend([artifact["coord"]]) http_files.extend([ " http_file(", " name = \"%s\"," % http_file_repository_name, @@ -499,6 +501,8 @@ def _pinned_coursier_fetch_impl(repository_ctx): http_files.extend(_get_jq_http_files()) + http_files.extend(["maven_artifacts = [\n%s\n]" % (",\n".join([" \"%s\"" % artifact for artifact in maven_artifacts]))]) + repository_ctx.file("defs.bzl", "\n".join(http_files), executable = False) repository_ctx.file( "netrc", diff --git a/private/coursier_utilities.bzl b/private/coursier_utilities.bzl index 86cca9476..741558580 100644 --- a/private/coursier_utilities.bzl +++ b/private/coursier_utilities.bzl @@ -46,6 +46,10 @@ def strip_packaging_and_classifier(coord): return ":".join(coordinates) def strip_packaging_and_classifier_and_version(coord): + coordinates = coord.split(":") + # Support for simplified versionless groupId:artifactId coordinate format + if len(coordinates) == 2: + return ":".join(coordinates) return ":".join(strip_packaging_and_classifier(coord).split(":")[:-1]) # TODO: Should these methods be combined with _parse_maven_coordinate_string in specs. diff --git a/private/rules/artifact.bzl b/private/rules/artifact.bzl index c2aae141f..8d82e3c08 100644 --- a/private/rules/artifact.bzl +++ b/private/rules/artifact.bzl @@ -1,9 +1,10 @@ load("//:specs.bzl", "parse") load("//private:constants.bzl", "DEFAULT_REPOSITORY_NAME") +load("//private:coursier_utilities.bzl", "strip_packaging_and_classifier_and_version") def artifact(a, repository_name = DEFAULT_REPOSITORY_NAME): - artifact_obj = _parse_artifact_str(a) if type(a) == "string" else a - return "@%s//:%s" % (repository_name, _escape(artifact_obj["group"] + ":" + artifact_obj["artifact"])) + artifact_str = _make_artifact_str(a) if type(a) != "string" else a + return "@%s//:%s" % (repository_name, _escape(strip_packaging_and_classifier_and_version(artifact_str))) def maven_artifact(a): return artifact(a, repository_name = DEFAULT_REPOSITORY_NAME) @@ -11,9 +12,6 @@ def maven_artifact(a): def _escape(string): return string.replace(".", "_").replace("-", "_").replace(":", "_") -def _parse_artifact_str(artifact_str): - pieces = artifact_str.split(":") - if len(pieces) == 2: - return {"group": pieces[0], "artifact": pieces[1]} - else: - return parse.parse_maven_coordinate(artifact_str) +def _make_artifact_str(artifact_obj): + # TODO: add support for optional type, classifier and version parts in artifact_obj case + return artifact_obj["group"] + ":" + artifact_obj["artifact"]