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...
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?
7 Answers
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.
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
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.
It's go mod download. For more info check go help mod
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" }}')