-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: Using go modules in a child cmd directory with local path in replace directive needs valid version #38972
Comments
separate modules are independent, there is no guarantee the parent directories exist that said the wiki also recommends against multi module repositories for most use cases |
I'm not certain there is a bug here. If you want the module at /cc @bcmills, who may be able to explain this better. |
I agree with @seankhliao and @toothrot's assessment. For your use-case, it is likely preferable to keep the command within the same module as the library. If you want to maintain a separate module and allow it to be fetched with |
@montanaflynn, could you explain why you wanted to split |
@bcmills one use case is dependency management. We have something of a standard library in go internally that has a ton of depdencies and it's a bit of a pain to have to install them all for every repo in our ci workflow. We would like to version them in lcok step though for sanity's sake |
@seankhliao @toothrot @bcmills thanks, I removed the second cmd module and my problem went away. I was under the impression that in order to use the library I needed to create a module with it as a dependency. |
Thanks for following up. Since you have a viable alternative and the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Created a new project with a
./cmd/notify/
directory to allow users to use as a library or install a cli program easily usinggo get github.com/montanaflynn/notify-cli/cmd/notify
.The
./cmd/notify/go.mod
is set to use the local package path usingreplace directive
along with require set to version v0.0.0 as mentioned in the wiki replace section:What did you expect to see?
I expected
go get github.com/montanaflynn/notify-cli/cmd/notify
to work.What did you see instead?
If I change the require directive to a valid version it works:
Even though it's said to require v0.0.6 it does successfully use the local path to install the latest version. I've had a lot of confusion surrounding the migration to go modules and I think this is a common pattern a lot of Go developers are using so I think a best practice example in the wiki would be helpful. Also I wonder why the require is needed at all or if there's a better way to signal that the it's a local dependency.
The text was updated successfully, but these errors were encountered: