Before I used go dep
, but now office ensure the official tool is go mod
.
When I use go dep
, I can add local dependency packages to vendor and ignored
in Gopkg.toml
to ignore search the package from repo. I can execute go dep update
normally.
Now I use go mod
, I also add local dependence package to vendor and add it exclude
in go.mod
. But when i execute go mod tidy
, it remove the package even though my project exist import xxx
.
What did i do:
modify go.mod exclude privaterepo.com/bb/bb
copy my local module to vendor because the local module is on a private repo which not support https.
vendor |-github.com/aa/aa |-privaterepo.com/bb/bb
So, what should I do to add local package to vendor and avoid go mod
remove it?
So, what should I do to add local package to vendor and avoid go mod remove it?
Well, I think you cannot do this. This is not how it works. go mod vendor
manages your vendor folder.
Instead of exclude
ing you package from go.mod you should add a replace
directive to instruct the go tool to look up the package not from privaterepo.com but from the local filesystem. Quoting from https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive
replace also can be used to inform the go tooling of the relative or absolute on-disk location of modules in a multi-module project, such as:
replace example.com/project/foo => ../foo
So in your case: Do not try to manually put privaterepo.com/bb/bb in vendor, but have it somewhere outside the current project and use
replace privaterepo.com/bb/bb => ../bb
And let go mod
copy this stuff from the filesystem to your vendor.