I have a very large Go project that depends on github.com/golang/mock
. Unfortunately, this package is no longer maintained, and the developers have directed people to use the fork at go.uber.org/mock
. So I'd like to replace the github.com/golang/mock
dependency with go.uber.org/mock
.
As I understand it, this is exactly what go.mod's replace
directive is for (allowing you to replace a dependency without having to change the import path in every single file). So, replacing this module with the fork should be as easy as adding the following line to my go.mod
:
replace github.com/golang/mock => go.uber.org/mock v0.2.0
Unfortunately, this is causing errors when trying to run any go
command:
$ go mod tidy
...
go: go.uber.org/mock@v0.2.0 used for two different module paths (github.com/golang/mock and go.uber.org/mock)
What am I doing wrong here?
You can view the repo/commit here if necessary.
According to the doc of the replace directive:
Regardless of whether a replacement is specified with a local path or module path, if the replacement module has a go.mod file, its module directive must match the module path it replaces.
The replace
directive can not be used here.
Since go.uber.org/mock
is published with a different module path, I think you have to treat it as a totally different module than github.com/golang/mock
.