为了账号安全,请及时绑定邮箱和手机立即绑定

“go mod tidy”与“go build”的行为

“go mod tidy”与“go build”的行为

Go
ibeautiful 2023-07-17 13:53:25
假设我有一个具有以下结构的项目:+-- app/+-- otherstuff/+-- test/+-- go.mod+-- go.sum+-- main.go我可以通过运行以下命令来确保go.mod不包含未使用的依赖项go mod tidy:# 1) Verify that no dependency containing the name "modern-go" is found on go.mod$ grep 'modern-go' go.mod<-- Empty (nothing found) (OK)# 2) Run "go mod tidy", verify that nothing changes (i.e. go.mod is already clean)$ go mod tidy -vunused github.com/modern-go/concurrentunused github.com/modern-go/reflect2<-- messages above are displayed, but go.mod did not change# 3) Verify that go.mod did not change$ grep 'modern-go' go.mod<-- Empty (nothing found) (OK)现在,如果我运行go build,go.mod则会更新:# 4) Run "go build"$ go build# 5) go.mod was updated by "go build":$ grep 'modern-go' go.mod    github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect    github.com/modern-go/reflect2 v1.0.1 // indirect我不明白这是怎么回事。我预计go mod tidy会保持go.mod干净的状态,go build因此运行不会改变它。有任何想法吗?
查看完整描述

1 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

您所期望的行为通常是正确的。

Go 1.13 在这方面进行了一些修复。


查看完整回答
反对 回复 2023-07-17
  • 1 回答
  • 0 关注
  • 69 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信