title: Behaviour of "go mod tidy" vs "go build"
body: <p>Suppose I have a project with the following structure:</p>
  
  <pre><code>+-- app/
  +-- otherstuff/
  +-- test/
  +-- go.mod
  +-- go.sum
  +-- main.go
  </code></pre>
  
  <p>I can make sure <code>go.mod</code> does not contain unused dependencies by running <code>go mod tidy</code>:</p>
  
  <pre><code># 1) Verify that no dependency containing the name "modern-go" is found on go.mod
  $ grep 'modern-go' go.mod
  &lt;-- 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
  &lt;-- messages above are displayed, but go.mod did not change
  
  
  # 3) Verify that go.mod did not change
  $ grep 'modern-go' go.mod
  &lt;-- Empty (nothing found) (OK)
  </code></pre>
  
  <p>Now, if I run <code>go build</code>, <code>go.mod</code> gets updated:</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>I can't figure out what's going on here. I expected <code>go mod tidy</code> would leave <code>go.mod</code> on a clean state, and that running <code>go build</code> would therefore not change it.</p>
  
  <p>Any ideas?</p>