cmd/go: allow go.mod to import a pre-defined replace definitions file #40933
Labels
FeatureRequest
FrozenDueToAge
modules
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
I have a project where I'm using various local modules using following syntax:
If I have to add a new dependency to the project then I have to open each and every package and manually edit the
go.mod
file and rungo mod tidy
to fetch new dependencies.The common problem while working with multiple local modules is that, we need to constantly add, remove or update replace definitions.
This can be improved by allowing go mod to import replace definitions from a pre-defined file
for example:
This way we can re-use existing replace definitions across various local projects without creating a separate git server.
Using this method if we made changes to one replace definition file then those changes will reflect on all local modules that import this file.
If we have un-used replace definitions, then
go mod tidy
does not make use of them, so it is safe to have un-used definitions that will soon be used while doing local development.I also noticed that if a module has updated and correct replace definitions, but imports another module that has old and incorrect replace definition, then
go mod tidy
fails.With import definitions method we can can make sure that all local modules have updated and correct replace definitions.
I noticed that there is yet another proposal that recommends the use of
go.local.mod
file for defining replace definitions that will only be used for local development. It also makes it easy to exclude files that should not be commited to a git server.#26640
We can combine both mechanisms,
using
go.local.mod
+ importing replace definitions intogo.local.mod
from an existing filewhich I mentioned in above issue.
This way git repository won't have unnecessary commits, plus we will be able to specify replace definitions in one local file and changes will be reflected in all local modules that import this file.
This will ease the development flow while working on multiple modules simultaneously that depend on each other and require constant updates to
replace
definitions. We can make changes to one replace definitions file and changes will reflect on all local modules.This is just a suggestion, we can come up with better ways for re-importirg existing replace defintions.
Let me know what you think.
The text was updated successfully, but these errors were encountered: