Cairne.Chan
Cairne.Chan

Reputation: 81

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

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
)

Upvotes: 1

Views: 1107

Answers (1)

icza
icza

Reputation: 417412

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 ./...

Upvotes: 4

Related Questions