I'm wondering how to work with local libraries. Let's say I want to develop two vgo projects in parallel, a my-project
and a my-util
project which is used by my-project
. Of course my-util
is available at a remote repository, but since it's not feasible to commit all my changes in here into the master branch just to make them available (and testable) in my-project
, I want to use the local version of my-util
instead. Similar to the good old mvn clean install
in Java.
I figure this must be realized with the replace
directive. But this means that I need to manipulate my go.mod
in my-project
in a way I don't want to commit later. Is there any way around this problem except removing all my replace
directives before the commit and just to re-add them afterwards?
Is there something like a go_local.mod
which contains the replace
directives and could be put on .gitignore
? Or some kind of environment variable where I can define replacements? Or at least an IDE which allows to ignore replace
directives in the go.mod
on commit?
Or am I taking the wrong approach and is there a more convenient alternative for the replace
approach in my case?
Looks like Go comes up with better solution finally. With 1.18 it is possible to create a workplace file where replace
directives can be applied: https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
So a go.work
like this should work:
go 1.18
use (
./my-project // location of the go.mod of my project
)
replace github.com/NotX/my-util => ./my-util // location of go.mod
So starting from the go.work
file location the command go test ./my-project/...
should now use the local utility repo.
1.18 isn't release yet though, so that might change bit.