Skip to content
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: allow go.mod to import a pre-defined replace definitions file #40933

Open
p554157atch opened this issue Aug 20, 2020 · 2 comments
Open

cmd/go: allow go.mod to import a pre-defined replace definitions file #40933

p554157atch opened this issue Aug 20, 2020 · 2 comments

Comments

@p554157atch
Copy link

@p554157atch p554157atch commented Aug 20, 2020

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.

#26640

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.

@bcmills
Copy link
Member

@bcmills bcmills commented Aug 20, 2020

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.)

CC @jayconrod @matloob

@bcmills bcmills added the modules label Aug 20, 2020
@bcmills bcmills changed the title GO.MOD allow importing pre-defined replace definitions file cmd/go: allow go.mod to import a pre-defined replace definitions file Aug 20, 2020
@bcmills bcmills added this to the Unplanned milestone Aug 20, 2020
@p554157atch
Copy link
Author

@p554157atch p554157atch commented Aug 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.