Thank you, Jan.  Apparently where I went wrong was assuming that the
dependency had to be listed in go.mod.  (i.e., using the names from your
example, foo/go.mod needed to have a "require bar" in it).  That is what I
was struggling to achieve; it never occurred to me that it could be
omitted.  I'm still surprised it works without that; it seems weird to have
a dependency on another module and *not* list it with all of the other
dependencies.

At any rate, I have it working now based on your help — much appreciated.
Steve


On Tue, Oct 11, 2022 at 11:22 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Oct 12, 2022 at 4:49 AM Steve Roth <st...@rothskeller.net> wrote:
> >
> > I'd appreciate help with setting up a workspace, involving two modules
> that exist only on my local disk and not in any SCM.  I understand how to
> create the workspace and use both modules in it.  What I can't figure out
> is how to add a dependency from mod1 to mod2 in mod1's go.mod file.
> >
> > The supported means of adding dependencies in go.mod files is the go get
> command.  But if I go into mod1's directory and run "go get path/to/mod2",
> it tries to download it from github and fails.  I cannot figure out how to
> tell go get to use the version that's on my local disk, even though the
> workspace says it should.
> >
> > Similarly, I can't figure out how to add the necessary go.mod and go.sum
> entries manually.  The documentation explicitly warns against trying to do
> so, anyway.
> >
> > It seems like this is exactly the case workspaces were designed for,
> developing two modules at once, and yet I've had no success in getting it
> set up.  Any suggestions?
>
> For example:
>
> jnml@3900x:~/tmp/modules/bar$ rm -rf *
> jnml@3900x:~/tmp/modules/bar$ go mod init example.com/bar
> go: creating new go.mod: module example.com/bar
> jnml@3900x:~/tmp/modules/bar$ echo 'package bar; func Y() {}' > bar.go
> jnml@3900x:~/tmp/modules/bar$
>
> and
>
> jnml@3900x:~/tmp/modules/foo$ rm -rf *
> jnml@3900x:~/tmp/modules/foo$ go mod init example.com/foo
> go: creating new go.mod: module example.com/foo
> jnml@3900x:~/tmp/modules/foo$ echo 'package foo; import "example.com/bar";
> func X() { bar.Y() }' > foo.go
> jnml@3900x:~/tmp/modules/foo$ go build -v
> foo.go:1:21: no required module provides package example.com/bar; to add
> it:
> go get example.com/bar
> jnml@3900x:~/tmp/modules/foo$ go work init
> jnml@3900x:~/tmp/modules/foo$ go work use ../bar
> jnml@3900x:~/tmp/modules/foo$ go build -v
> directory . is contained in a module that is not one of the workspace
> modules listed in go.work. You can add the module to the workspace using
> go work use .
> jnml@3900x:~/tmp/modules/foo$ go work use .
> jnml@3900x:~/tmp/modules/foo$ go build -v
> jnml@3900x:~/tmp/modules/foo$
>
> HTH
>
> -j
>

-- 
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/CAAnpqKFVsSXXi3qEFWhrXDGqFkxT85xJ__ZsBDnJFuDWJtELuA%40mail.gmail.com.

Reply via email to