安装goreleaser提示异常和解决办法

328 阅读1分钟

项目中运行go get github.com/goreleaser/goreleaser@v1.18.1 出错:

go: downloading github.com/goreleaser/goreleaser v1.18.1
panic: internal error: can't find reason for requirement on github.com/golang/mock@v1.5.0

goroutine 1 [running]:
cmd/go/internal/modget.(*resolver).updateBuildList.func1({{0xc000511f20?, 0xc00051cb58?}, {0xc000026e80?, 0xc000afe320?}})
        ...

错误解决办法:

使用语句
go install github.com/goreleaser/goreleaser@v1.18.1

错误原因: 在Go 1.16及以后:go get不再用于安装二进制工具,而主要用于更新依赖项,会更改当前模块的依赖关系。造成出错。
因此,在Go 1.16以后执行这个命令,它将把 github.com/goreleaser/goreleaser 添加到 go.mod 中作为依赖,而不再安装该工具.

在Go 1.16及以后:go install 可以直接安装指定版本的二进制工具到$GOBIN(通常是$HOME/go/bin)目录中,而不会修改go.mod文件。这是推荐的安装Go工具的方法。