title: How to resolve conflicting go module dependencies when a top-level module and one of its sub-modules are separately imported as separate versions?
body: <p>I have two dependencies in my project.</p>
  
  <p><code>go.mod</code>:</p>
  
  <pre><code>module github.com/test-org/test-repo
  
  go 1.12
  
  require (
      github.com/foo/bar v1.0.0
      github.com/raz/mataz v1.0.0
  )
  </code></pre>
  
  <hr>
  
  <p>After running <code>go mod download</code>, those two dependencies result in two different versions of a <code>github.com/shared/dependency</code> to be downloaded. The interesting thing is that the <code>github.com/shared/dependency</code> contains sub-modules, e.g.:</p>
  
  <pre><code>dependency
    -- go.mod
    -- api
        -- go.mod
  </code></pre>
  
  <p>Inspecting the downloaded modules shows two versions are downloaded to my local machine:</p>
  
  <p><code>ls ${GOPATH}/pkg/mod/github.com/shared</code>:</p>
  
  <pre><code>[dir] dependency    [dir] dependency@v1.1.0
  </code></pre>
  
  <p><code>ls ${GOPATH}/pkg/mod/github.com/shared/dependency</code>:</p>
  
  <pre><code>[dir] api@v1.2.0
  </code></pre>
  
  <hr>
  
  <p>Looking at the contents of these directories:</p>
  
  <p><code>${GOPATH}/pkg/mod/github.com/shared/dependency@v1.1.0</code>:</p>
  
  <p>The file contents of the whole repo in v1.1.0, including the <code>api</code> folder with its own <code>go.mod</code> file.</p>
  
  <p><code>${GOPATH}/pkg/mod/github.com/shared/dependency/api@v1.2.0</code>:</p>
  
  <p>The file contents of the <code>api</code> folder of the repo in v1.2.0, including the <code>go.mod</code> file.</p>
  
  <hr>
  
  <p>Finally, I have a <code>.go</code> file in my <code>test-repo</code> with the following setup:</p>
  
  <pre><code>package test-package
  
  import (
      "github.com/foo/bar"
  )
  
  func MyFunc() {...bar.NewBar()...}
  </code></pre>
  
  <p>When I try to run a test of <code>MyFunc</code> (that exists elsewhere), I get an <code>unknown import path...ambiguous import...</code> error message. e.g.</p>
  
  <p><code>go test github.com/test-org/test-repo/test-package -test.run=TestMyFunc -v</code>:</p>
  
  <pre><code>unknown import path "github.com/shared/dependency/api": ambiguous import: found github.com/shared/dependency/api in multiple modules:
      github.com/shared/dependency v1.1.0 (${GOPATH}/pkg/mod/github.com/shared/dependency@v1.1.0/api)
      github.com/shared/dependency v1.2.0 (${GOPATH}/pkg/mod/github.com/shared/dependency/api@v1.2.0)
  </code></pre>
  
  <p>The error points to the <code>import</code> line of the <code>.go</code> file importing <code>github.com/shared/dependency/api</code> in the <code>github.com/foo/bar</code> repo. It doesn't know which <code>api</code> to choose in my local <code>${GOPATH}/pkg/mod</code> folder, given the two versions available:</p>
  
  <ol>
  <li><code>${GOPATH}/pkg/mod/github.com/shared/dependency@v1.1.0/api</code></li>
  <li><code>${GOPATH}/pkg/mod/github.com/shared/dependency/api@v1.2.0</code></li>
  </ol>
  
  <hr>
  
  <p>Is there any way that I can make that <code>go test</code> call work (solve the dependency conflicts)? Neither of my two dependencies explicitly call out downloading the full <code>shared/dependency@v1.1.0</code>, but for some reason it gets pulled in. If that weren't there, it would seemingly fix the issue.</p>