Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: 'go build' on a module absolute path while cwd is in GOPATH builds in GOPATH mode #27612
What did you do?
If I init a go module outside my gopath and then run go build from that directory, it works as expected.
If I run go build /absolute/dir/of/module but my current working directory is inside my gopath, go build will try to look up dependencies in my gopath (and fail if they're not there).
This seems wrong. if I give a path to the code, the path of the code should be what determines whether or not to use modules, no the current directory of where go build is run. Otherwise, I get different behavior for building the same code in the same place dependent on the CWD, which is extremely confusing and hard to debug.
Addendum.... this came up as a problem because I would build go code outside my gopath, and the go tool downloaded the dependencies, but then I'd try to build the same code in the same location, but with the working directory inside gopath, and the go tool wouldn't be able to find the dependencies (because it was looking in gopath).
Building two things is not this issue. But -
However, if I run go build on exactly one thing, there's only possible correct behavior, and there not the behavior that occurs right now. I'm not sure where the confusion is with that.