protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Using `maven` as the repo name causes duplicate warnings when using bzlmod

Open jschaf opened this issue 9 months ago • 3 comments

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.

Proposed fixes

There are a few ways to fix the logline:

  1. Patch protobuf in the Bazel Central Registry rewrite maven to protobuf_maven.
  2. Modify the protobuf repo to rewrite maven to protobuf_maven.
  3. 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.

jschaf avatar May 13 '24 22:05 jschaf

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 avatar Jun 25 '24 08:06 bnordli

@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.

shs96c avatar Jun 25 '24 13:06 shs96c

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~'

mpatou-openai avatar Aug 22 '24 20:08 mpatou-openai

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~'

Can you open a separate issue with details?

JasonLunn avatar Oct 03 '24 20:10 JasonLunn

@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.

@jschaf / @bnordli - did the suggestion from @shs96c work for you?

JasonLunn avatar Oct 03 '24 20:10 JasonLunn

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

jschaf avatar Oct 03 '24 23:10 jschaf

If you send a PR I can get it routed to the right reviewers.

JasonLunn avatar Oct 07 '24 14:10 JasonLunn

@JasonLunn https://github.com/protocolbuffers/protobuf/pull/18641

jschaf avatar Oct 07 '24 16:10 jschaf