You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm dealing with multiple go projects in my organization. For each project, we decided to have a custom configuration for GOPATH. We did it to separate Go projects so that each project has its own GOPATH. This method works well for us until recently when we upgraded the go version to 1.19.5. But it's the same with version 1.20.
NOTE that this issue only occurs if the GOPATH is set to be inside of the project directory.
Note that go mod tidy will not consider packages in the main module in directories named testdata or with names that start with . or _ unless those packages are explicitly imported by other packages.
When setting the GOPATH to an ignored path in the directory (e.g. <project-dir>/.go). It works without any issue. However, we are not sure if this is a good practice or not and will it cause any issues?
I'm not a go module expert and we don't want any core dump in our production code. :)
Run go mod tidy again, you should see some errors:
$ go mod tidy
test/go/pkg/mod/github.com/davecgh/[email protected]/spew: import path "test/go/pkg/mod/github.com/davecgh/[email protected]/spew" should not have @version
test/go/pkg/mod/github.com/pmezard/[email protected]/difflib: import path "test/go/pkg/mod/github.com/pmezard/[email protected]/difflib" should not have @version
What did you expect to see?
I expect to see a successful go mod tidy with exit code 0 no matter how many times I run it.
It used to work without any problem in version 1.16.8.
What did you see instead?
$ go mod tidy
test/go/pkg/mod/github.com/davecgh/[email protected]/spew: import path "test/go/pkg/mod/github.com/davecgh/[email protected]/spew" should not have @version
test/go/pkg/mod/github.com/pmezard/[email protected]/difflib: import path "test/go/pkg/mod/github.com/pmezard/[email protected]/difflib" should not have @version
The text was updated successfully, but these errors were encountered:
working as intended. go stores downloaded dependencies in GOPATH/go/pkg by default.
Modules are intended to be independent projects, covering everything within it, acting independently of GOPATH except to use it as a (shared) cache. You shouldn't need to create new GOPATHs for each project in module mode, and what you're doing now will clearly cause errors.
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
@seankhliao Your answer does not preclude having a GOPATH dir per project, but makes an unsubstantiated claim that having a GOPATH dir per project causes a problem. I truly believe this is worth looking into, because the behavior did change somewhere between v1.16 and later, and there's no mention in Go documentation whatsoever.
Nor Go documentation places any limitations as to where the GOPATH directory can or cannot be, and we decided that our chosen location is as good as any.
Would you be so kind to present any proof as to why, and I quote from your answer, "what you're doing now will clearly cause errors."
What version of Go are you using (
go version
)?But issues occur in the following versions too:
1.20
,1.19.5
,1.19.4
,1.19.3
,1.19.2
,1.19.1
,1.18.X
s, and1.17.X
s.Does this issue reproduce with the latest release?
Yes, I can reproduce it in go
1.20
.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm dealing with multiple go projects in my organization. For each project, we decided to have a custom configuration for
GOPATH
. We did it to separate Go projects so that each project has its own GOPATH. This method works well for us until recently when we upgraded the go version to1.19.5
. But it's the same with version1.20
.NOTE that this issue only occurs if the
GOPATH
is set to be inside of the project directory.Quoted from https://go.dev/ref/mod#go-mod-tidy
When setting the GOPATH to an ignored path in the directory (e.g.
<project-dir>/.go
). It works without any issue. However, we are not sure if this is a good practice or not and will it cause any issues?I'm not a go module expert and we don't want any core dump in our production code. :)
Source Files:
main.go
go.mod
I also tested it using other different dependencies and some of them reproduce this issue, some of them don't.
go.sum
These are the steps to reproduce the issues:
go mod tidy
, the first time should be successful.go mod tidy
again, you should see some errors:What did you expect to see?
I expect to see a successful
go mod tidy
with exit code 0 no matter how many times I run it.It used to work without any problem in version
1.16.8
.What did you see instead?
The text was updated successfully, but these errors were encountered: