-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: module dependencies added from different go.mod files of single module at different versions #35884
Comments
Although the sample reproduction is contrived, I ran into this issue in a real scenario when converting repositories with a circular dependency to modules (where both repos also pointed to a common repository where a submodule was later created). Because minor versions aren't collapsed, the circular import made it such that the module was considering both its current dependencies and the dependencies of its previous version, which was very confusing to reason about. If the underlying issue itself won't be fixed, it would be helpful to have documentation somewhere that notes that the module dependency graph will consider dependencies of all versions of dependent modules, including all different minor/patch versions of the same module. |
/cc @jayconrod @bcmills |
I think the issue here is that both modules
The requirement on There are a couple ways to resolve this. You could try eliminating the requirement on You could tag a new version of Hope this helps. Closing since this is working as intended, but I'm happy to answer questions. |
@jayconrod thanks for chiming in -- adding It would be helpful for me to clear up this conceptual question, though:
If that's just the way things are then that's that, but this is the portion that I would specifically like to understand. That's the part that felt like a bug/incorrect behavior on my end without further knowledge -- since my understanding was that only one major version of a module was used per build, the fact that the dependencies of multiple different versions of the same module were being used in analysis seemed strange to me and was unexpected. |
The requirement on a newer version of This comes up mostly when a single large module is split into submodules. For example, take a look at the
That's true when it comes to loading and building packages, but not for reading To summarize though, think of each version of each module in a directed graph. Requirements in The (Sorry this isn't documented somewhere more obvious by the way. I'm working on improving the documentation for 1.14 (#33637)). |
Thanks! Yes, I think the main source of confusion for me was that import path conflicts could happen based on dependencies introduced by different versions of the same module -- I thought that these conflicts would only matter if they existed at the build list level, but it makes sense that this would be an error even at the module dependency construction level (and thus consolidating module versions to a single one at that point doesn't prevent the error). I believe I fully understand the contracts now, and appreciate the tip for adding the requirement to the submodules to help prevent issues for other consumers. Thanks! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Created a module import graph that has an ambiguous import that is provided by two different version of the same dependent module and attempted to build.
Specifically:
go.mod
containsrequire github.com/nmiyake/test-repo-c v0.0.0-20191127215535-3c89b55e2851
go.mod
containsrequire github.com/nmiyake/test-repo-b v1.0.0
go.mod
containsrequire github.com/nmiyake/test-repo-c/smile v1.0.0
go.mod
containsrequire github.com/nmiyake/test-repo-b v1.1.0
andrequire github.com/nmiyake/test-repo-d v1.0.0
go build
for test-repo-aI created this scenario and pushed them to public repositories -- cloning and attempting to build https://github.com/nmiyake/test-repo-a demonstrates the issue.
Simplified textual representation:
What did you expect to see?
I expected this to succeed.
The module graph contains both B@v1.1.0 and B@v1.0.0, and together these cause an import path conflict. However, the module specification states that only a single major version of a module will be used within a build, so this import path conflict shouldn't matter -- ultimately the build will only use one version of B, so it's confusing to me that the build can fail due to conflicts between different version of the same module.
My expectation is that, when constructing the module graph, modules that have multiple different minor versions will be version-selected and then collapsed to a single one so that dependencies provided by multiple different versions of the same module aren't considered.
What did you see instead?
Build fails due to ambiguous import path:
It is possible to work around this by creating an empty module at "github.com/test-repo-c" and adding a "replace" directive:
However, all upstream modules that consume "test-repo-a" must add this as well, and it doesn't address the underlying issue of why it's possible for a conflict to occur due to dependencies provided by the same minor/patch version of a single module.
The text was updated successfully, but these errors were encountered: