-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: support local
directive in go.mod
#51779
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
Comments
CC @bcmills |
local
directive in go.modlocal
directive in go.mod
Go 1.18 has workspaces. Could they be used in your use case? |
Also note that this is otherwise a duplicate of #26640. |
go.work seems a local workspace and not be pushed to remote repo in best practice? If I split monorepo to three git repos, go.work can be easily used for me to modify my code. |
I feel they are not duplicated. |
I would like to add a further issue to consider here. We have a similar project structure, but we also use vendoring in the root project. Using the example from the description, this means the |
Any feedback about this proposal? |
This proposal has been added to the active column of the proposals project |
As envisioned above, this feature would be incompatible with modules. The specific goal seems to be to have something that is like A separate problem would be how to infer the actual version to use. The go command does not fundamentally operate on Git repositories, and there is no way to express "use the same Git commit for m/sub as for m". So even if that constraint were not computationally problematic, it still depends on breaking down abstractions that we currently have. To work on a collection of related modules in a single repository and have the convenience of having them all bound together while working in a git clone of the repo, the answer is go.work. The answer for making go install work is to tag the sub-modules, then update the appropriate require lines in the command module, then tag the command module. |
This proposal has been declined as infeasible. |
Why
One go.mod is not reasonable for monorepo
For example, we have a repo with structure as below
If the repo consumers hope to import
client
andapi
pkg, they have to import the whole module and indirectly import dependencies ofserver
pkg.Only three choices for this situation.
client/v0.1.0
replace
directiveFor choice 1, we have to manage more git repos and submit more PRs for a feature.
For choice 2, we have to tag
api
andclient
, then change the go.mod version and tag main module.For choice 3,
replace
directive has some problems now.replace
directive for monorepoThe below lines are used in many go.mod files.
However, go install is not worked if
replace
directive exists(See #44840, #40276)Another problem of
replace
is ifclient
also importsapi
and replaces it. consumers have to usereplace
in go.mod again to ensureapi
module's version.Design
local
directive for all modules which are imported from same git repo.In main module
in client module
in consumer module
go mod graph for consumer
Compatibility
No compatibility problem
Unresolved Issues
Git tag
client/v0.0.1
will be conflict withv0.0.1
in semantic. There are two solutions:client/v0.0.1
will override thev0.0.1
tag.Alternatives
require
as the local module. (also good to me)replace
directive.The text was updated successfully, but these errors were encountered: