Why is Go trying to upgrade my go.mod
to Go 1.21?
On oapi-codegen we recently had a report that Go 1.21 results in go test
being unable to run without having go mod tidy
'd the project.
If you're running Go 1.21:
$ go version
go version go1.21.0 linux/amd64
Then checking out the project (as of the latest commit and running make tidy
shows the following diff:
diff --git go.mod go.mod
index dd8b906..2122b0e 100644
--- go.mod
+++ go.mod
@@ -1,6 +1,8 @@
module github.com/deepmap/oapi-codegen
-go 1.20
+go 1.21
+
+toolchain go1.21.0
Through discussion in the Go community (Gopher) Slack, it appears that this is due to one of the modules in my dependency tree using Go 1.21, and therefore Go is upgrading the whole project to Go 1.21.
As noted in the Go 1.21 release notes, the go
directive now defines an explicit minimum, whereas before it could be possible to try and build a future version of Go code, and maybe it would just work, or fail.
I've blogumented that process to determine the versions in a separate blog post.
But if you're seeing this issue, your best course of action is to take the changes and upgrade the whole project to 1.21.