bazel-contrib / rules_jvm_external

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

Depending on both POM and JAR of the same maven artifact causes symlink error at artifacts pinning #1267

Open cerisier opened 1 month ago

cerisier commented 1 month ago

Description

After updating to 6.4, when trying to pin artifacts, bazel reported the following error:

ERROR: An error occurred during the fetch of repository 'rules_jvm_external~~maven~unpinned_maven':
   Traceback (most recent call last):
    File "external/rules_jvm_external~/private/rules/coursier.bzl", line 1077, column 84, in _coursier_fetch_impl
        artifact.update({"file": _relativize_and_symlink_file_in_coursier_cache(repository_ctx, artifact["file"], coursier_cache_path)})
    File "external/rules_jvm_external~/private/rules/coursier.bzl", line 231, column 31, in _relativize_and_symlink_file_in_coursier_cache
        repository_ctx.symlink(absolute_path, repository_ctx.path(artifact_relative_path))
Error in symlink: java.io.IOException: Could not create symlink <skipped> (File exists)

After investigation, I found that 2 of my dependencies were transitively depending on the same maven artifact, one with explicit jar packaging and one without (default to pom), specifically:

And the introduction of 8388befc8504ac9df779fad8940ec4a112e16fe0, such case will cause a duplicate entry in the dep_tree since both entries for the pom and the jar coordinates of the same artifact will both have their file point the the same .jar.

https://github.com/bazel-contrib/rules_jvm_external/blob/8388befc8504ac9df779fad8940ec4a112e16fe0/private/rules/coursier.bzl#L955-L958