如何用govendor实现类似go get ./...的批量依赖托管功能?
Great question! You're right that govendor get ./... doesn't behave the same way as go get ./..., but there are two straightforward ways to pull all your project's dependencies into the vendor directory in one go:
Method 1: Vendorize dependencies already in your GOPATH
If you've already run go get ./... to download dependencies to your local GOPATH, you can quickly copy them into the vendor folder:
- Initialize govendor in your project directory:
govendor init - Copy all external dependencies (everything not part of your project or the standard library) into vendor:
govendor add +external
This command scans your project's imports, identifies all external packages already present in your GOPATH, and copies them into the vendor directory while updating vendor.json.
Method 2: Fetch dependencies directly into vendor (no pre-run go get)
If you haven't downloaded the dependencies yet, you can have govendor fetch them directly into the vendor folder:
- First initialize govendor:
govendor init - Fetch all missing dependencies (packages your project imports that aren't in vendor or your local project):
govendor fetch +missing
This command will reach out to remote repositories, download all required dependencies, and place them straight into vendor—no need to clutter your GOPATH first.
Why govendor get ./... doesn't work
The govendor get command is designed to fetch specific packages and their dependencies, but it doesn't interpret the ./... wildcard the same way go get does. It won't recursively scan your project's imports to find all required dependencies, which is why it fails to replicate the behavior you're looking for.
To verify all dependencies are properly added, you can run:
govendor list
This will show all packages tracked by govendor, including those in the vendor directory.
内容的提问来源于stack exchange,提问作者SomeGuyFortune




