@@ -925,12 +925,43 @@ def make_coursier_dep_tree(
925
925
if (exec_result .return_code != 0 ):
926
926
fail ("Error while fetching artifact with coursier: " + exec_result .stderr )
927
927
928
- return deduplicate_and_sort_artifacts (
928
+ dep_tree = deduplicate_and_sort_artifacts (
929
929
json .decode (repository_ctx .read (repository_ctx .path ("dep-tree.json" ))),
930
930
artifacts ,
931
931
excluded_artifacts ,
932
932
_is_verbose (repository_ctx ),
933
933
)
934
+ return rewrite_files_attribute_if_necessary (repository_ctx , dep_tree )
935
+
936
+ def rewrite_files_attribute_if_necessary (repository_ctx , dep_tree ):
937
+ # There are cases where `coursier` will download both the pom and the
938
+ # jar but will include the path to the pom instead of the jar in the
939
+ # `file` attribute. This differs from both gradle and maven. Massage the
940
+ # `file` attributes if necessary.
941
+ # https://github.com/bazelbuild/rules_jvm_external/issues/1250
942
+ amended_deps = []
943
+ for dep in dep_tree ["dependencies" ]:
944
+ if not dep .get ("file" , None ):
945
+ amended_deps .append (dep )
946
+ continue
947
+
948
+ # You'd think we could use skylib here to do the heavy lifting, but
949
+ # this is a dependency of `maven_install`, which is loaded in the
950
+ # `repositories.bzl` file. That means we can't rely on anything that
951
+ # comes from skylib yet, since the repo isn't loaded. If we could
952
+ # call `maven_install` from `setup.bzl`, we'd be fine, but we can't
953
+ # do that because then there'd be nowhere to call the
954
+ # `pinned_maven_install`. Oh well, let's just do this the manual way.
955
+ if dep ["file" ].endswith (".pom" ):
956
+ jar_path = dep ["file" ].removesuffix (".pom" ) + ".jar"
957
+ if repository_ctx .path (jar_path ).exists :
958
+ dep ["file" ] = jar_path
959
+
960
+ amended_deps .append (dep )
961
+
962
+ dep_tree ["dependencies" ] = amended_deps
963
+
964
+ return dep_tree
934
965
935
966
def remove_prefix (s , prefix ):
936
967
if s .startswith (prefix ):
@@ -1032,7 +1063,7 @@ def _coursier_fetch_impl(repository_ctx):
1032
1063
# This file comes from maven local, so handle it in two different ways depending if
1033
1064
# dependency pinning is used:
1034
1065
# a) If the repository is unpinned, we keep the file as is, but clear the url to skip it
1035
- # b) Otherwise, we clear the url and also simlink the file from the maven local directory
1066
+ # b) Otherwise, we clear the url and also symlink the file from the maven local directory
1036
1067
# to file within the repository rule workspace
1037
1068
print ("Assuming maven local for artifact: %s" % artifact ["coord" ])
1038
1069
artifact .update ({"url" : None })
0 commit comments