title: Importing Go modules from a different repository in the same file system
body: <p>I have two separate Go repositories. One contains an application, another a shared library that the application would like to use. Neither are in $GOPATH.</p>
  
  <pre><code>~/projects/
  ├── myapplication
  │   ├── go.mod
  │   └── myapplication.go
  └── mylibrary
      ├── go.mod
      └── mylibrary.go
  </code></pre>
  
  <hr>
  
  <p><strong>mylibrary/go.mod</strong></p>
  
  <pre><code>module example.com/mylibrary
  
  go 1.14
  </code></pre>
  
  <p><strong>mylibrary/mylibrary.go</strong></p>
  
  <pre><code>package mylibrary
  
  var Message = "Hello, World!"
  </code></pre>
  
  <hr>
  
  <p><strong>myapplication/go.mod</strong></p>
  
  <pre><code>module example.com/myapplication
  
  go 1.14
  </code></pre>
  
  <p><strong>myapplication/myapplication.go</strong></p>
  
  <pre><code>package myapplication
  
  import (
      "fmt"
      "example.com/mylibrary"
  )
  
  func main() {
      fmt.Println(mylibrary.Message)
  }
  </code></pre>
  
  <hr>
  
  <p>I have no reason to believe that the above should work as the application has no way of finding out where the library is. How do I?</p>
  
  <p>I have tried the following with now results.</p>
  
  <ul>
  <li>adding <code>~/projects/mylibrary</code> to GOPATH</li>
  <li>running  <code>go install</code> for mylibrary</li>
  </ul>
  
  <p>Running <code>go build</code> for the application gives:</p>
  
  <pre><code>myapplication $ go build
  go: finding module for package example.com/mylibrary
  myapplication.go:5:2: cannot find module providing package example.com/mylibrary: unrecognized import path "example.com/mylibrary": reading https://example.com/mylibrary?go-get=1: 404 Not Found
  </code></pre>
  
  <p>I can see that it is reaching out to example.com to find the repository (understandably). But how can I tell it to look for somewhere locally first?</p>