如何让 Go 模块自动拉取依赖的最新版本而不是指定特定的标签?

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

How could go module auto pull the latest version of dependency instead of assign a specific tag

问题

通常我会标记依赖项并在go.mod文件中进行引用,例如:

require (
    private-gitlab.com/domain/common v1.0
)

每当我更新private-gitlab.com/domain/common时,我会给它分配一个新的标记,比如v1.1,然后更改要求:

require (
    private-gitlab.com/domain/common v1.1
)

一旦应用了微服务架构,有多个微服务需要这个依赖项,因此我需要将它们的标记从v1.0更改为v1.1

Go模块是否支持latest/snapshot标记(类似于Java Maven的snapshot),以便自动检测和拉取依赖项的最新版本,例如:

require (
    private-gitlab.com/domain/common qa@latest
)
英文:

In general I tag the dependency and require it in go.mod file, for example:

require (
    private-gitlab.com/domain/common v1.0
)

Whenever I update private-gitlab.com/domain/common, I assign a new tag to it such as v1.1, then change the requirement

require (
    private-gitlab.com/domain/common v1.1
)

Once apply microservices architecture, there are multiple microservices require this dependency, so that I should change their tags from v1.0 to v1.1

Does go module support latest/snapshot tag (something like java maven snapshot) so that it would auto detect and pull the latest version of dependency, like

require (
    private-gitlab.com/domain/common qa@latest
)

答案1

得分: 4

Go的模块系统应该提供可复现的构建。因此,如果有新版本可用,go工具在不经用户同意的情况下不能随意从一个构建中获取新版本。

用户必须显式地更新依赖项,例如通过运行:

go get example.com/theirmodule@latest

如果您想查看是否有任何有更新(新版本)的依赖项,可以运行:

go list -m -u all

如果您想更新您的模块的所有直接和间接依赖项(不包括测试依赖项),可以运行:

go get -u ./...

要更新所有直接和间接依赖项,包括测试依赖项,可以运行:

go get -u -t ./...
英文:

Go's module system ought to provide reproducible builds. So without the user's consent, the go tool cannot just fetch a newer version arbitrarily from one build to another if a newer version is available.

The user has to update the dependencies explicitly, e.g. by running:

go get example.com/theirmodule@latest

If you want to see if there are any dependencies that have updates (newer versions), you may run:

go list -m -u all

If you want to update all direct and indirect dependencies of your module (excluding test dependencies), you may run:

go get -u ./...

To update all direct and indirect dependencies including test dependencies, you may run:

go get -u -t ./...

huangapple
  • 本文由 发表于 2021年12月1日 17:50:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/70182073.html
匿名

发表评论

匿名网友

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

确定