-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
What version of Go are you using (go version)?
go1.11 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOARCH=amd64
GOHOSTARCH=amd64
GOHOSTOS=windows
What did you do?
I have a local project outside of my GOPATH that consumes packages from another related local project, also outside of GOPATH.
/proj1/somepkg
/proj2/
proj2's go.mod redirects the package path: replace example.com/proj1 => ../proj1
This builds perfectly using go build - but if I want to do vendored builds, using go mod vendor copies contents of proj1/somepkg into proj2/vendor/example.com/proj1/somepkg/.
What did you expect to see?
Since proj1 and proj2 are both local code, and Go Modules are meant to facilitate local code outside of a GOPATH, I had hoped local code could be left in place - then go build -mod=vendor would use a combination of the go.mod require/replace specs to build with local code requirements and vendored external package requirements.
What did you see instead?
go build -mod=vendor seems to make the logical assumption that all imported external modules are under the vendor/ subdirectory. It seems to be a binary choice - either all vendored or all versioned modules.
This makes sense to me. I understand this design choice and the need for compatibility with dep. But for the sake of local code, it would be nice to have total control over where the vendored module requirements are found.
As a (failed) workaround I tried using go mod vendor to collect dependencies, removed my copied source, added a replace for all external dependencies with the vendored path in go.mod, and go build normally. However, Go Modules isn't happy:
go: parsing vendor\github.com\google\gops\go.mod: open <path>proj2\vendor\github.com\google\gops\go.mod: The system cannot find the file specified.
go: parsing vendor\github.com\globalsign\mgo\go.mod: open <path>proj2\vendor\github.com\globalsign\mgo\go.mod: The system cannot find the file specified.
go: error loading module requirements