bazel-contrib / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Apache License 2.0
337 stars 256 forks source link

Ensure that the `pom` classifier isn't always downloaded #1251

Closed shs96c closed 2 months ago

shs96c commented 2 months ago

Closes #1250

honnix commented 1 month ago

Not exactly sure how it happens, but I think this change results in duplicated symlink creation, which obviously fails. It seems duplicated entries appear in amended_deps.

honnix commented 1 month ago

I tried this patch and it worked:

diff --git a/private/rules/coursier.bzl b/private/rules/coursier.bzl
index 530a90b..28e3746 100644
--- a/private/rules/coursier.bzl
+++ b/private/rules/coursier.bzl
@@ -954,6 +954,8 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree):
         # `pinned_maven_install`. Oh well, let's just do this the manual way.
         if dep["file"].endswith(".pom"):
             jar_path = dep["file"].removesuffix(".pom") + ".jar"
+            if is_dep(jar_path, amended_deps):
+                continue
             if repository_ctx.path(jar_path).exists:
                 dep["file"] = jar_path

@@ -963,6 +965,12 @@ def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree):

     return dep_tree

+def is_dep(jar_path, deps):
+    for dep in reversed(deps):
+        if jar_path == dep.get("file", None):
+            return True
+    return False
+
 def remove_prefix(s, prefix):
     if s.startswith(prefix):
         return s[len(prefix):]