bazel-contrib / bazel-contrib/rules_jvm_external

Allow suppressing a version conflict

Open
#435 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
373
Forks
301
Avg merge
6d 3h
Merged PRs (30d)
5

Description

I'm trying to solve a thorny dependency conflict, and it seems like I could really use a way to say "I know you think this is a version conflict, but trust me, it's okay". I'm open to other solutions I may be missing.

Here's a stripped-down version of my install:

```python
maven_install(
artifacts = [
"io.grpc:grpc-netty:1.17.1",
"io.netty:netty-codec-http2:4.1.44.Final",
"io.etcd:jetcd-core:0.3.0",
],
repositories = [
"https://jcenter.bintray.com/",
],
)
```

* `io.grpc:grpc-netty:1.17.1` has a dependency on `io.netty:netty-codec-http2:[4.1.30.Final]`. This is an exact version match -- the `.44` version is a conflict.
* In practice, the later version (`.44`) is perfectly fine, gRPC is just very cautious about compatibility.
* Some other dep (not shown here) needs `io.netty:netty-codec-http2:4.1.44.Final`, the older `.30` version is not okay.
* For app-specific reasons not important here, I can't easily change the version of any of these libraries.

Therefore, I would like a way to declare that `io.grpc:grpc-netty` should depend on `4.1.44.Final` of `io.netty:netty-codec-http2`, regardless of what Maven says.

Now, what I can do is use an exclusion and a custom declaration:
```python
maven_install(
artifacts = [
maven.artifact(
group = "io.grpc",
artifact = "grpc-netty",
version = "1.17.1",
exclusions = [
maven.exclusion("io.netty", "netty-codec-http2"),
],
),
"io.netty:netty-codec-http2:4.1.44.Final",
],
repositories = [
"https://jcenter.bintray.com/",
],
)

# some BUILD.bazel
java_library(
name = "io_grpc_grpc_netty",
exports = ["@maven//:io_grpc_grpc_netty"],
runtime_deps = ["@maven//:io_netty_netty_codec_http2"],
)
```

This works... as long as it's only _my_ code that depends on `grpc-netty`. Whenever I want to use another Maven library that has this as a dep (such as `jetcd-core` listed above), I have to apply the same technique (exclusion, custom library rule), and so on transitively, which gets pretty annoying.

I originally thought I could use `override_targets` for this, but there doesn't seem to be a way to reference the _original_ `@maven//:io_grpc_grpc_netty` target if I override it, so I can't construct my custom target.

Any ideas for a clean solution to this kind of problem?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the dependency conflict with the maven_install example, then inspect how maven_install, exclusions, and override_targets handle transitive dependencies. Done means providing a supported way to select the requested Netty version without repeating custom exclusions and library rules for every dependent Maven artifact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.