rules_jvm_external
rules_jvm_external copied to clipboard
Use alias instead of override destination.
Resolves https://github.com/bazelbuild/rules_jvm_external/issues/582
Problem
That issue is caused by overrides to fully-qualified labels being duplicative with their non-overridden counterparts. For example, consider ndbench-core, which takes a dependency on both com.codahale.metrics:metrics-core
and io.dropwizard.metrics:metrics-core
. Those two libraries expose many of the same fully-qualified classes, and we'd like to only have one version of each class on the classpath.
To accomplish this, we could use an override like:
override_targets = {
"com.codahale.metrics:metrics-core": "@regression_testing//:io_dropwizard_metrics_metrics_core",
},
so that the "old" codahale metrics-core is replaced with the "new" dropwizard one.
Currently, this results in generated deps like:
...
jvm_import(
...
deps = [
...
"@regression_testing//:io_dropwizard_metrics_metrics_core",
...
":io_dropwizard_metrics_metrics_core",
...
],
...
Analysis of this fails with errors like:
ERROR: /private/var/tmp/_bazel_sam_shadwell/7db21a72dc367049bac9ba2882a68834/external/regression_testing/BUILD:2469:11: Label '@regression_testing//:io_dropwizard_metrics_metrics_core' is duplicated in the 'deps' attribute of rule 'com_netflix_ndbench_ndbench_core'
Solution
As suggested by @jdai8, the solution is to instead reference the generated alias in deps (instead of eagerly resolving the alias as is done now).
So now we generate deps like:
alias(
name = "com_codahale_metrics_metrics_core",
actual = "@regression_testing//:io_dropwizard_metrics_metrics_core",
visibility = ["//visibility:public"],)
...
jvm_import(
...
deps = [
...
":com_codahale_metrics_metrics_core",
...
":io_dropwizard_metrics_metrics_core",
...
],
...
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
For more information, open the CLA check for this pull request.
Ping @shs96c - it looks reasonable to me. (I'm working with Sam)
Welp, we're going on 2 years now and no word from anyone.
While I still think this would be a positive change, I'm no longer working on Bazel-related things. Closing this PR to clean up my personal PR dashboard.