简体   繁体   中英

Should `go build` fail if version in `go.mod` is lower than actual?

I have go 1.15 specified in the go.mod file.

The current compiler version is the following:

➜ go version
go version go1.14.4 linux/amd64

Yet, go build still successfully builds a binary.

Is this an expected behaviour? Not sure I can find explanation in the modules description.

Yes, this is an expected behaviour.

The go.mod is more of a tool for dependencies and package management than a tool for managing the output of the build process. That's why, if you're not using any features from 1.15, it should still be able to be built.

The funny part is that if you try to build a project set to a version higher than the one that you're using (ie 1.15 built with go tool 1.14) and you mark in your go.mod that it needs to use the higher version, it'll show up in the build process:

# temp/test-go-build
./main.go:10:15: o.Redacted undefined (type url.URL has no field or method Redacted)
note: module requires Go 1.15

So the go tool tries it's best to fit your needs but won't block you from getting where you want to go (get it?).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM