rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

Documentation for resolving `Found duplicate artifact versions`

Open aryeh-looker opened this issue 2 years ago • 6 comments

Would be great to document best-practices for resolving duplicate artifact versions

https://github.com/bazelbuild/rules_jvm_external/blob/master/coursier.bzl#L649

aryeh-looker avatar Jun 13 '22 21:06 aryeh-looker

+1 I am currently not sure how to go about resolving duplicate artifacts.

desh-woes avatar Jan 10 '23 00:01 desh-woes

Duplicate artefacts are listed when the same artefact is in the list given to maven_install. Quite often, this is because you're pulling in a constant defined in another repo and including that in your maven_install's artifacts parameter.

shs96c avatar Jan 10 '23 12:01 shs96c

Does it work with having multiple android version installed? How can I resolve it?

rules_jvm_external/coursier.bzl:646:18: Found duplicate artifact versions
    com.google.guava:guava has multiple versions 31.1-jre, 29.0-android, 31.0.1-android

AAverin avatar Apr 28 '23 15:04 AAverin

Quite often, this is because you're pulling in a constant defined in another repo and including that in your maven_install's artifacts parameter.

A typical case of this is:

com.google.guava:guava has multiple versions 32.1.3-android, 33.0.0-jre

if you have (something) like:

maven_install(
    artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS + [
        "junit:junit:4.13.2",
        "com.google.guava:guava:33.0.0-jre",

Because IO_GRPC_GRPC_JAVA_ARTIFACTS has com.google.guava:guava:32.1.3-android.

Here is one way to fix this, as I have done here:

# This is required so that we can use duplicate_version_warning (below) and fixes
# the "com.google.guava:guava has multiple versions 32.1.3-android, 33.0.0-jre" problem.
IO_GRPC_GRPC_JAVA_ARTIFACTS_WITHOUT_GUAVA = [item for item in IO_GRPC_GRPC_JAVA_ARTIFACTS if item != "com.google.guava:guava:32.1.3-android"]

maven_install(
    artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS_WITHOUT_GUAVA + [
        "junit:junit:4.13.2",
        "com.google.guava:guava:33.0.0-jre",
    ],
    duplicate_version_warning = "error",
)

vorburger avatar Mar 17 '24 14:03 vorburger

The duplicate warning occurs when using bzlmod on an empty maven list. The trick is to add an explicit maven.artificact for guava.

bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_java", version = "7.5.0")
bazel_dep(name = "rules_jvm_external", version = "6.1")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.artifact(
    artifact = "guava",
    exclusions = ["com.google.code.findbugs:jsr305"],
    group = "com.google.guava",
    version = "31.1-jre",
)
maven.install(
    name = "maven",
    lock_file = "//:maven_install.json",
    artifacts = [],
)

jschaf avatar May 13 '24 21:05 jschaf

Hey folks, I'm also getting these and I'd like to clean them up... However, from what I can tell my dependencies are transitive (I depend on grpc-kotlin and that depends on grpc-java). Any ideas on how I can tell it which version to use?

ratnikov avatar Jun 08 '24 02:06 ratnikov