Search CTRL + K

检查哪个依赖导致 go.mod 版本增加

在引入一些依赖,或者更新依赖版本后经常会遇到 go.mod 文件中 go 版本增加,有时我们不希望变更 go 版本,因此需要快速找出哪个依赖导致了 go 版本增加。

  1. 罗列所有依赖版本
go list -mod=readonly -m -f '{{if and (not .Main) .GoVersion}}{{.Path}} => Go {{.GoVersion}}{{end}}' all
  1. 罗列超过某个版本的依赖
go list -mod=readonly -m -f '{{if and (not .Main) .GoVersion}}{{.Path}} => Go {{.GoVersion}}{{end}}' all | awk '{split($NF, v, "."); if (v[1] > 1 || (v[1] == 1 && v[2] > 18)) print;}'