hi all,

When using a `go get` in a project (module) that has a `go work` 
configured, I'm getting errors "cannot find module providing package ...", 
for the packages that are located on `go work use ...` locations. Meaning, 
`go get` seems to ignore (?) `go.work` file.

Likely this is deliberate and I'm missing some point, but ... for my use 
case, I would love to have `go get` ignore the packages that are imported 
from directories in `go.work`, and just "get" the other ones.

Is there a way to have that ? (I couldn't find any flag in `go get`). Or 
any other ideas ?

many thanks!
Jan

ps.: Here how to reproduce the issue:

Director "~/work/a/"

$ go mod init "github.com/joe/a"
$ cat > main.go
package main
import (
        "fmt"
        "github.com/joe/b"
)

func main() {
        fmt.Printf("Hello from joe/a!\n")
        b.Message()
}
$ go work init ; go work use .  ~/work/b

In directory "~/work/b":

$ go mod init "github.com/joe/b"
$ cat > b.go
package b
import "fmt"
func Message() {
        fmt.Printf("Hello from joe/b!\n")
}

Back to directory "~/work/a":

$ go run .
Hello from joe/a!
Hello from joe/b!

*$ go get*

*github.com/joe/a imports        github.com/joe/b: cannot find module 
providing package github.com/joe/b*

A bit more context, in case it matters: I don't need to `go get` to get 
anything for the packages in `go.work`, but I (think) need it to get any 
potential missing other packages. I run `go get` (without specifying the 
packages) each time before executing a Jupyter notebook cell (in GoNB a 
jupyter notebook kernel), because I don't know ahead of time which new 
packages need to be fetched. 

Also curiously, if I use a `replace` directive in `go.mod` then `go get` 
works fine, it seems to ignore the replaced package. In my example:

$ go mod edit --replace github.com/job/b=/home/janpf/work/b

But a `replace` directive in `go.work` doesn't seem parsed by `go get`:

$ go work edit --replace github.com/job/b=/home/janpf/work/b

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/200cdca3-2dfd-41b1-a407-c30071803520n%40googlegroups.com.

Reply via email to