cmd/go: allow go.mod to import a pre-defined replace definitions file
p554157atch opened this issue · 3 comments
I have a project where I'm using various local modules using following syntax:
module private/hello
go 1.14
replace private/cli => /mnt/data/data/go/src/private/cli
replace private/customutil => /mnt/data/data/go/src/private/customutil
replace private/postgresdb => /mnt/data/data/go/src/private/postgresdb
replace private/logger => /mnt/data/data/go/src/private/logger
...
...
...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 run go 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:
module private/hello
go 1.14
replace_definitons /home/coder/replace_definitions.mod
...
...
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.
We can combine both mechanisms,
using go.local.mod + importing replace definitions into go.local.mod from an existing file
which 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.
Personally, I would rather we support a separate per-user or per-module file (as in #26640) rather than define some kind of import mechanism. (go.mod files already have replace as a sort of import mechanism, but of course that doesn't import the replacements.)
Hello, Thanks for the links.
We can combine both mechanisms,
using go.local.mod + importing replace definitions into go.local.mod from an existing file
which 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.
I have updated above issue to consider how it might work with go.local.mod 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.
The motivating usecases should be covered by go.work