How to get all dependency files for a program

I make a program in Go and after completing the code, if I want to run this code on other pc or VM, then it does not get all the dependency package files. How can I get all dependency files?

141239 次浏览

You can run go get -d ./... from a directory of your project to download all go-gettable dependencies.
Or copy all src subdirectory from your GOPATH to the destination machine.
... is a special pattern, tells to go down recursively.

You can use godep save in your local pc where you complete your program. godep save collect all the dependency files for you. When you move to other pc, just copy the Godep folder with your code and it will solve your problems.

Try

go list -f '\{\{ join .Imports "\n" }}'

or

go list -f '\{\{ join .Deps "\n" }}'

The second will list all subdependencies, the first only the directly imported packages.

Below command works for me it downloads all the dependencies.

go get -u -v -f all

Best way ever is get the list and iterate installing the packages, this works so fine:

while read l; do go get -v "$l"; done < <(go list -f '\{\{ join .Imports "\n" }}')

It's go mod download. For more info check go help mod

If you are using module mode, you can try go mod tidy, as described here.