1Vendoring in std and cmd
4The Go command maintains copies of external packages needed by the
5standard library in the src/vendor and src/cmd/vendor directories.
7In GOPATH mode, imports of vendored packages are resolved to these
8directories following normal vendor directory logic
11In module mode, std and cmd are modules (defined in src/go.mod and
12src/cmd/go.mod). When a package outside std or cmd is imported
13by a package inside std or cmd, the import path is interpreted
14as if it had a "vendor/" prefix. For example, within "crypto/tls",
15an import of "golang.org/x/crypto/cryptobyte" resolves to
16"vendor/golang.org/x/crypto/cryptobyte". When a package with the
17same path is imported from a package outside std or cmd, it will
18be resolved normally. Consequently, a binary may be built with two
19copies of a package at different versions if the package is
20imported normally and vendored by the standard library.
22Vendored packages are internally renamed with a "vendor/" prefix
23to preserve the invariant that all packages have distinct paths.
24This is necessary to avoid compiler and linker conflicts. Adding
25a "vendor/" prefix also maintains the invariant that standard
26library packages begin with a dotless path element.
28The module requirements of std and cmd do not influence version
29selection in other modules. They are only considered when running
30module commands like 'go get' and 'go mod vendor' from a directory
33Maintaining vendor directories
36Before updating vendor directories, ensure that module mode is enabled.
37Make sure GO111MODULE=off is not set ('on' or 'auto' should work).
39Requirements may be added, updated, and removed with 'go get'.
40The vendor directory may be updated with 'go mod vendor'.
41A typical sequence might be:
43 cd src
44 go get -d golang.org/x/net@latest
45 go mod tidy
46 go mod vendor
48Use caution when passing '-u' to 'go get'. The '-u' flag updates
49modules providing all transitively imported packages, not only
50the module providing the target package.
52Note that 'go mod vendor' only copies packages that are transitively
53imported by packages in the current module. If a new package is needed,
54it should be imported before running 'go mod vendor'.
View as plain text