@@ -176,13 +176,21 @@ not need updates, such as in a continuous integration and testing system.
176
176
The "go get" command remains permitted to update go.mod even with -mod=readonly,
177
177
and the "go mod" commands do not take the -mod flag (or any other build flags).
178
178
179
- If invoked with -mod=vendor, the go command assumes that the vendor
180
- directory holds the correct copies of dependencies and ignores
181
- the dependency descriptions in go.mod.
179
+ If invoked with -mod=vendor, the go command loads packages from the main
180
+ module's vendor directory instead of downloading modules to and loading packages
181
+ from the module cache. The go command assumes the vendor directory holds
182
+ correct copies of dependencies, and it does not compute the set of required
183
+ module versions from go.mod files. However, the go command does check that
184
+ vendor/modules.txt (generated by 'go mod vendor') contains metadata consistent
185
+ with go.mod.
182
186
183
187
If invoked with -mod=mod, the go command loads modules from the module cache
184
188
even if there is a vendor directory present.
185
189
190
+ If the go command is not invoked with a -mod flag and the vendor directory
191
+ is present and the "go" version in go.mod is 1.14 or higher, the go command
192
+ will act as if it were invoked with -mod=vendor.
193
+
186
194
Pseudo-versions
187
195
188
196
The go.mod file and the go command more generally use semantic versions as
@@ -380,22 +388,28 @@ the format of the cached downloaded packages.
380
388
381
389
Modules and vendoring
382
390
383
- When using modules, the go command completely ignores vendor directories.
384
-
385
- By default, the go command satisfies dependencies by downloading modules
386
- from their sources and using those downloaded copies (after verification,
387
- as described in the previous section). To allow interoperation with older
388
- versions of Go, or to ensure that all files used for a build are stored
389
- together in a single file tree, 'go mod vendor' creates a directory named
390
- vendor in the root directory of the main module and stores there all the
391
- packages from dependency modules that are needed to support builds and
392
- tests of packages in the main module.
393
-
394
- To build using the main module's top-level vendor directory to satisfy
395
- dependencies (disabling use of the usual network sources and local
396
- caches), use 'go build -mod=vendor'. Note that only the main module's
397
- top-level vendor directory is used; vendor directories in other locations
398
- are still ignored.
391
+ When using modules, the go command typically satisfies dependencies by
392
+ downloading modules from their sources and using those downloaded copies
393
+ (after verification, as described in the previous section). Vendoring may
394
+ be used to allow interoperation with older versions of Go, or to ensure
395
+ that all files used for a build are stored together in a single file tree.
396
+
397
+ The command 'go mod vendor' constructs a directory named vendor in the main
398
+ module's root directory that contains copies of all packages needed to support
399
+ builds and tests of packages in the main module. 'go mod vendor' also
400
+ creates the file vendor/modules.txt that contains metadata about vendored
401
+ packages and module versions. This file should be kept consistent with go.mod:
402
+ when vendoring is used, 'go mod vendor' should be run after go.mod is updated.
403
+
404
+ If the vendor directory is present in the main module's root directory, it will
405
+ be used automatically if the "go" version in the main module's go.mod file is
406
+ 1.14 or higher. Build commands like 'go build' and 'go test' will load packages
407
+ from the vendor directory instead of accessing the network or the local module
408
+ cache. To explicitly enable vendoring, invoke the go command with the flag
409
+ -mod=vendor. To disable vendoring, use the flag -mod=mod.
410
+
411
+ Unlike vendoring in GOPATH, the go command ignores vendor directories in
412
+ locations other than the main module's root directory.
399
413
` ,
400
414
}
401
415
0 commit comments