bazel-contrib / bazel-contrib/rules_jvm_external

Support classifiers in artifact overrides

Open
#447 1 comment 0 reactions 0 assignees View on GitHub
type: feature request
Dominant language
Java
Stars
373
Forks
301
Avg merge
7d 17h
Merged PRs (30d)
3

Description

We have an existing dependency on [`org.yaml:snakeyaml:1.26`](https://mvnrepository.com/artifact/org.yaml/snakeyaml/1.26). We want to add a new dependency to [`com.github.javafaker:javafaker:1.0.2`](https://mvnrepository.com/artifact/com.github.javafaker/javafaker/1.0.2).

Unfortunately, the latter has a dependency on `org.yaml:snakeyaml:jar:android` instead of the main artifact. When we use the following repository declaration, it defines both `@maven//:org_yaml_snakeyaml` and `@maven//:org_yaml_snakeyaml_android`, which have conflicting class definitions.

```starlark
maven_install(
artifacts = [
"com.github.javafaker:javafaker:1.0.2",
"org.yaml:snakeyaml:1.26",
],
repositories = [
"https://jcenter.bintray.com/",
],
override_targets = {
# (doesn't work)
# "org.yaml:snakeyaml:jar:android": "@maven//:org_yaml_snakeyaml",
},
)
```

We would like a way to force it to only use a single version, the unclassified one.

The same workaround as in #435 works -- add `org.yaml:snakeyaml` to the other artifact's `exclusions`, and define a custom `java_library` that depends on the desired version.

It seems like an obvious solution would be to support classifiers in `override_targets` as shown above, but maybe there are other, better ways to address this.

Contributor guide

Open the contributing guide

Research direction

Start with the maven_install declaration and override_targets example in the issue, then reproduce the dependency graph involving javafaker and both SnakeYAML artifacts. Trace how classified Maven coordinates become generated targets. Done means a classifier-specific override can select the unclassified artifact without generating conflicting duplicate targets, with coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.