假设我有一个具有以下结构的项目:
+-- 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 -v
unused github.com/modern-go/concurrent
unused 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
不会改变它。
有什么想法吗?
答案 0 :(得分:0)