Open aryeh-looker opened 2 years ago
+1 I am currently not sure how to go about resolving duplicate artifacts.
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.
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
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",
)
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 = [],
)
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?
Would be great to document best-practices for resolving duplicate artifact versions
https://github.com/bazelbuild/rules_jvm_external/blob/master/coursier.bzl#L649