如何使”go get”获取传递依赖项?

huangapple go评论88阅读模式
英文:

How can I make "go get" get transitive dependencies?

问题

我在GitHub上有一个Go项目,地址是github.com/usmanismail/gpns,人们可以使用以下命令拉取该项目:

go get github.com/usmanismail/gpns

然而,我的项目依赖于一些其他项目,比如goconfig。我该如何设置我的项目,以便当人们使用go get命令拉取我的项目时,也能获取到所需的依赖项呢?

英文:

I have a go project in github at github.com/usmanismail/gpns which people can pull in using:

go get github.com/usmanismail/gpns

However, my project depends on a few other projects such as goconfig. How can I setup my project such that when people go get my project they will also get the required dependencies.

答案1

得分: 3

go get已经获取了所有的依赖项:

Get会下载并安装由导入路径指定的包,以及它们的依赖项。

如果你需要更多的控制,可以考虑使用像godep这样的工具来管理你的依赖项。

英文:

go get already gets all the dependencies:

> Get downloads and installs the packages named by the import paths, along with their dependencies.

If you need more control consider vendoring your dependencies using a tool like godep.

答案2

得分: 1

更新所有依赖项,包括传递依赖项的方法如下:

go get -u
go get -u all
go mod tidy

第一个命令更新直接依赖项,第二个命令更新传递依赖项。

英文:

To update all dependencies including transitive:

go get -u
go get -u all
go mod tidy

The first one updates the direct dependencies, the second one does the transitive ones.

答案3

得分: 0

如果你在谈论测试依赖项,而不是使用go get,你可以尝试使用go get -t github.com/usmanismail/gpns

如果你在谈论二进制依赖项、工具等,我认为你需要告诉用户这是一个要求,或者提供一个自动安装依赖项的脚本。

参考:https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies

英文:

If you are talking about test-dependencies, instead of go get, you could try go get -t github.com/usmanismail/gpns

If you are talking about binary dependencies, tools etc, I think you will have to tell the users that this is a requirement or provide a script that installs the dependencies automatically.

ref. https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies

huangapple
  • 本文由 发表于 2013年12月27日 01:30:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/20788732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定