-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: default to GO111MODULE=on #41330
Comments
I rather liked the gopath, it was a clean way to organize stuff, it made working on multiple inter-operating things much nicer, can we retain a way to keep it optionally... just have that not be the default? |
I still check out my repos in "GOPATH organization" when working with modules, and you're welcome to do the same. If you want changes in one module to be used by another, the way to do that in a go.mod is to add a replace line.
And when I'm done with local development I remove that line again. This keeps the intended dependencies explicit. In contrast, the GOPATH approach of doing that replacement automatically means that your build is affected by old checkouts you happen to have lying around that you might have forgotten about. It means that the build you get on one machine can be different from another, even starting with the same version of the same top-level repo. And it means that the builds you get can be different from the ones another developer in the same project gets. Modules address all these reproducibility concerns. In addition to reproducibility, modules provide a clear way to handle proxying and secure downloads. When you git clone a project and then grab its dependencies, those dependencies are being cryptographically checked to make sure they're the same bits the original developer used. The only trusted part is the top-level "git clone". And for future evolution of Go itself, modules clearly mark which version of the Go language a particular tree of files is written in. This makes it possible to disable problematic features - for example, string(1), which many people think produces "1" but actually produces "\x01" (^A) - in later versions of Go by default while at the same time keeping older programs building (because they are explicitly marked as having been written for the older version of Go). There's more I could list. None of this is possible with GOPATH as it exists today. We can't move the ecosystem forward and start really depending on these important properties without retiring GOPATH. (You might ask: why not just add those things to GOPATH? The answer is: we did, and the result is Go modules.) |
Thanks Go team for all your hard work on this! Minor point: I noticed that When you're outside of
If |
Yes, sorry for the confusion: GOPATH mode (GO111MODULE=off) will eventually be removed. The GOPATH environment variable will be sticking around, since it is used to derive the default install directory (GOPATH/bin) as well as the location of the module and build caches (GOPATH/pkg). |
Thinking outloud, we could eventually deprecate |
@docmerlin I use this small git wrapper which clones into a GOPATH like layout https://github.com/icholy/git-get |
@mvdan, I see very little benefit to deprecating the GOPATH environment variable. Today I can set one variable to say "put all the automatic Go stuff over here". Changing that to setting three different variables doesn't seem like a win at all, and what happens when we add a fourth thing? |
Change https://golang.org/cl/255052 mentions this issue: |
In addition to the functionality changes, I think we need facelifting of the cmd/go documentation to be more module oriented. I just encountered an issue related to I also noticed GOPATH is mentioned throughout the documentation. When defaulting to enable modules, they may cause confusion, especially for new users who are not aware of all the history. |
About the documentation, thanks for bringing this up, I totally agree. I just opened #41427 to track updating the About |
Change https://golang.org/cl/255398 mentions this issue: |
We would now need new defaults for GOMODCACHE and GOBIN before doing the "deprecating GOPATH" part of this proposal. |
@nightlyone We're not planning to deprecate the |
This CL does not fix failures in ./gopls/internal/regtest, which will be fixed separately. In refactor/rename.TestDiff, add a go.mod file. In internal/imports.ProcessEnv.buildContext, set an I/O hook if GO111MODULE=off in ProcessEnv but not in the current process's environment. Context allows the user to set GOPATH, GOOS, GOARCH, and a few other environment variables, but not GO111MODULE. Context.Import may return different results than packages.Load if the latter is invoked with a GO111MODULE value that differs from the caller's environment. Setting an I/O hook forces Import to run in GOPATH mode, not invoking 'go list'. This is undocumented, but it should be stable while GOPATH is supported. For golang/go#41330 Change-Id: I5679e8941e32dc95b05c234cb2e3fec5cabebced Reviewed-on: https://go-review.googlesource.com/c/tools/+/255398 Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Jay Conrod <[email protected]>
I'm going to link to this issue in a wiki page and expect people might be tempted to add comments here. |
Change https://golang.org/cl/285112 mentions this issue: |
Back in Go 1.13 we tried defaulting to GO111MODULE=on but discovered a bunch of things that needed to be smoother before making it the default. Instead we added GO111MODULE=auto and made that the default, so that people with a go.mod could always get modules, but people without a go.mod would still get GOPATH mode.
The general plan since Go 1.11 to retire GOPATH mode has not changed. That's still an important step.
We believe Go 1.16 will have a smooth enough module experience to make it the default always. At that point GOPATH will be deprecated, to be removed entirely in some future Go version, perhaps Go 1.17.
We need to change the default soon, so that we can use it ourselves during the rest of the Go 1.16 cycle before shipping it in the release.
There are two important functionality changes remaining before we can change the default:
go get pkg@version
(go get pkg@latest
if you want the latest version) (cmd/go: 'go install' should install executables in module mode outside a module #40276).Once those are done, I believe we can flip the default. If there are any other blocking issues, please comment. Thank you.
The text was updated successfully, but these errors were encountered: