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/[email protected] 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:
The
replacedirective can not be used here.Since
go.uber.org/mockis published with a different module path, I think you have to treat it as a totally different module thangithub.com/golang/mock.