protobuf
protobuf copied to clipboard
Using `maven` as the repo name causes duplicate warnings when using bzlmod
Downstream bug in rules_jvm_external: https://github.com/bazelbuild/rules_jvm_external/issues/916
What version of protobuf and what language are you using?
v23.1
What did you expect to see
A clean build when using bzlmod.
What did you see instead?
DEBUG: $TMP/external/rules_jvm_external~/private/extensions/maven.bzl:154:14:
The maven repository 'maven' is used in two different bazel modules,
originally in '<my_workspace>' and now in 'protobuf'
Summarizing @shs96c in https://github.com/bazelbuild/rules_jvm_external/issues/916#issuecomment-1645527584
The common maven
repo name allows rulesets to contribute to the user's JARs. However, this implies that maven
is for the end user, not for transitive dependencies. If a ruleset needs private dependencies, it should use a custom namespace rather than the maven
namespace.
- rules_jvm_external uses rules_jvm_external_deps instead of
maven
. - rules_kotlin uses kotlin_rules_maven instead of
maven
.
Proposed fixes
There are a few ways to fix the logline:
- Patch protobuf in the Bazel Central Registry rewrite
maven
toprotobuf_maven
. - Modify the protobuf repo to rewrite
maven
toprotobuf_maven
. - Fetch the JARs manually without using Maven or rules_jvm_external. Trims the dependency graph a fair bit.
I think 2 is the best short-term option. If you're open to it, I can send a PR.
Can this please be fixed in both the v3 and v4 protobuf libraries in Bazel Central?
I cannot find a way to rename the maven
repository in our modules, because there needs to be a maven
repository defined (somewhere), and I cannot see there are support for multiple maven repositories when using bzlmod
(https://github.com/bazelbuild/rules_jvm_external/blob/master/docs/bzlmod.md).
@bnordli, assuming you're using bzlmod
, the examples list by @jschaf show you how to create a "private" set of dependencies for protobuf
. If you were to do this, you would require consumers of this ruleset to add the com.google.protobuf:protobuf-java
version they need to their own maven_install
or install
.
use_extension
also supports a new isolated
parameter, which may also be useful if you're working on a root project.
It seems latest version of protobuf in bcr are not using maven
anymore in bzlmod
(I can still see it in the WORKSPACE) and it leads to other set of issues:
no such package '@@[unknown repo 'maven' requested from @@protobuf~]//': The repository '@@[unknown repo 'maven' requested from @@protobuf~]' could not be resolved: No repository visible as '@maven' from repository '@@protobuf~'
It seems latest version of protobuf in bcr are not using
maven
anymore inbzlmod
(I can still see it in the WORKSPACE) and it leads to other set of issues:no such package '@@[unknown repo 'maven' requested from @@protobuf~]//': The repository '@@[unknown repo 'maven' requested from @@protobuf~]' could not be resolved: No repository visible as '@maven' from repository '@@protobuf~'
Can you open a separate issue with details?
@bnordli, assuming you're using
bzlmod
, the examples list by @jschaf show you how to create a "private" set of dependencies forprotobuf
. If you were to do this, you would require consumers of this ruleset to add thecom.google.protobuf:protobuf-java
version they need to their ownmaven_install
orinstall
.
use_extension
also supports a newisolated
parameter, which may also be useful if you're working on a root project.
@jschaf / @bnordli - did the suggestion from @shs96c work for you?
The isolate
parameter is marked experimental with a strong warning not to depend on it. I think using one of the alternatives in the first comment is a better approach.
Experimental. This parameter is experimental and may change at any time. Please do not depend on it. It may be enabled on an experimental basis by setting --experimental_isolated_extension_usages
If you send a PR I can get it routed to the right reviewers.
@JasonLunn https://github.com/protocolbuffers/protobuf/pull/18641