-
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose list of all artifacts, including transitive
And add support for :type and :classifier in defs.bzl:artifact() by internally using strip_packaging_and_classifier_and_version. To keep support for groupId:artifactId update strip_packaging_and_classifier_and_version implementation for that case. To be used like load("@maven//:defs.bzl", "maven_artifacts") and for example load("@rules_jvm_external//:defs.bzl", "artifact") load("@rules_jvm_external//:specs.bzl", "parse") all_maven_targets = [artifact(a) for a in maven_artifacts if not parse.parse_maven_coordinate(a).get("classifier", "compile") in ["sources", "native"]] java_export( name = "maven-transitive-deps-lib", maven_coordinates = "com.example.deps:%s:%s" % (name, "0.1"), visibility = ["//visibility:public"], runtime_deps = all_maven_targets, ) which makes "maven-transitive-deps-lib-pom" target available that can be useful for other tools like security scanners and/or dependabot
- Loading branch information
Showing
3 changed files
with
15 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
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) | ||
|
||
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"] |