go mod vendor: Usage, Options & Common CI Errors
Vendor dependencies into the repo for offline builds.
go mod vendor writes a vendor/ directory containing the source of all dependencies needed to build and test the module. When vendor/ is present, the go command builds from it by default.
What it does
Copies dependency packages into vendor/ and writes vendor/modules.txt describing them. With a vendor/ directory the default build mode becomes -mod=vendor, so builds use it and skip the network.
Common usage
go mod vendor # create/refresh vendor/
go build -mod=vendor ./... # force building from vendor/
go test -mod=mod ./... # ignore vendor/, use the cacheCommon CI error: inconsistent vendoring
go build fails with "inconsistent vendoring" because go.mod was changed but vendor/ (and vendor/modules.txt) was not regenerated. Fix: run go mod vendor and commit the updated vendor/ directory alongside go.mod, so they stay in sync.
Options
| Flag | Effect |
|---|---|
| -mod=vendor | Build from vendor/ |
| -mod=mod | Ignore vendor/, use cache |
| -v | List vendored packages |