I have project that uses an external library which has a bug in it. To fix the bug, what I tried to do was to clone the external library, place it in a sub-directory within the project, and fix it there. So if the external library is example.com/example/example/
, I just put it a folder named example
within my project, delete the example.com/example/example/
dependency from go.mod
, and replace all example.com/example/example/
import statements with myproject/example/
The problem is that the project doesn't compile. Whenever go build
is executed, it returns an error: no matching versions for query "latest"
. The only way I found to get the project to build is to delete the go.mod
file of the cloned external library, but that just doesn't seem right. So what's the right way to build such a project?
The right way to do it is using the replace directive.
The idea is to replace the the module name of the imported dependency from the top level go.mod
file, without changing the external dependency.
So all I had to do was to add replace example.com/example/example => ./example
to to top level go.mod
.