-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: no 'go get' command promotes an implicit dependency to an explicit one #43131
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
Comments
I think @heschik was asking about this a couple weeks ago, in the context of |
Yeah, I just used |
Change https://golang.org/cl/277355 mentions this issue: |
Change https://golang.org/cl/278812 mentions this issue: |
Change https://golang.org/cl/279528 mentions this issue: |
By default (and with -mod=readonly), the go command imports an error if a package provided by an implicitly required module is imported by a package in the main module. This import requires an update to go.mod: the module must be required explicitly. The package loader now provides a hint that 'go get' should be run on the importing package. This is preferred to 'go get' on the imported package, since that would add an "// indirect" requirement. For #43131 Change-Id: I0b353ce8ac8c4ddf1a9863544dfaf6c1964daf42 Reviewed-on: https://go-review.googlesource.com/c/go/+/279528 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
While testing some other behaviors for #36460, I noticed a curious interaction between
go get
and-mod=readonly
.If a package or test in the main module directly imports a package found in an implicit (transitive) dependency,
go build
andgo test
invocations for that package with-mod=readonly
will fail withupdates to go.mod needed
, because thego
command has always maintained the invariant that modules directly imported by the main module are explicit requirements.In this situation, the
go
command recommends runninggo mod tidy
, which is usually the first tool users ought to consider for dependency problems. However, a user who does not want to lose other temporary edits to thego.mod
file might prefer to instead usego get
to promote only one specific package instead.Unfortunately, if the module containing the package passed to
go get
is already transitively required at the requested version,go get
does not promote that module from an implicit dependency to an explicit one. (It will under lazy loading, but does not yet.)The user can work around this problem by running
go mod edit -require
to add the requirement explicitly, but we would rather not encourage users to reach forgo mod edit
to make dependency changes, as it does not ensure that the resulting requirements are consistent.Now that
-mod=readonly
is the default (#40728), I think users will be much more likely to encounter this awkward interaction. They may be frustrated by it, and might not consider thego mod edit
workaround.For Go 1.16, perhaps we should make
go get -d
always record explicit dependencies for the requested packages, which can be subsequently cleaned up with an explicitgo mod tidy
.CC @jayconrod @matloob
The text was updated successfully, but these errors were encountered: