Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent go build from overwriting version in go.mod

I have a go module that imports project foo. foo's latest tag says v1.4

when i do a go build in my project, it updates go.mod to say

module github.com/myid/mymod

require (
   github.com/myid/foo v1.4
)

I want it to use the master branch instead of v1.4 tag...so i did a go get github.com/myid/foo@master and it downloaded the master branch in pkg and updated go.mod to say

require (
    github.com/myid/foo v1-XXXXXXX-XXXXXXX
)

I verify that the hash is the same as master

but when i do go build again, it gets updated back to the latest tag.

how do i get it to use the master branch and not switch back to v1.4?

Thanks

like image 917
suppandi g Avatar asked Feb 13 '19 16:02

suppandi g


People also ask

What does +incompatible mean in Go mod?

mod and go. sum files with the suffix +incompatible , indicating that the selected version is not compatible with the original API for that path.

What does Go mod tidy?

mod requirements match the source code of the module, Go Modules provides the go mod tidy command. It will add any missing dependency being used by the source code to the list of requirements in the go. mod file, and can be useful to get the requirements list when we are trying to convert a project to Go Modules.

What is indirect in Go mod?

Indirect Dependencies You may see some dependencies in your go. mod file that are indirect (denoted by // indirect ). This means that one of your dependencies doesn't have its own go. mod file, so, the dependencies that it imports are included in your project's go. mod file.

Does Go build get dependencies?

As of Go 1.11, the go command (go build, go run, and go test) automatically checks and adds dependencies required for imports as long as the current directory or any parent directory has a go. mod.


1 Answers

Necro answer for anyone stumbling across this:

As of go 1.16 modules are no longer automatically bumped when using go build (etc..)

See: https://golang.org/doc/go1.16#go-command

like image 144
pentaphobe Avatar answered Sep 30 '22 21:09

pentaphobe