You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何用govendor实现类似go get ./...的批量依赖托管功能?

Solution for Vendorizing All Dependencies with Govendor

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:

  1. Initialize govendor in your project directory:
    govendor init
    
  2. 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:

  1. First initialize govendor:
    govendor init
    
  2. 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

火山引擎 最新活动