From d26542f3acb20cc7e5d936fa28a87047663f99d5 Mon Sep 17 00:00:00 2001 From: "kristina.pathak" Date: Wed, 8 May 2024 12:06:52 -0700 Subject: [PATCH] add explanation in readme, use go mod edit -require --- cmd/builder/README.md | 8 ++++---- cmd/builder/internal/builder/main.go | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/builder/README.md b/cmd/builder/README.md index cf2e07c43ad..bc30a4f6406 100644 --- a/cmd/builder/README.md +++ b/cmd/builder/README.md @@ -154,10 +154,10 @@ to only execute the compilation step. ### Avoiding the use of a new go.mod file -You can optionally skip creating a new `go.mod` file. -When the `--skip-new-go-module` command-line flag is supplied, -the build process issues a `go get` command for each component, -relying on the Go toolchain to update the enclosing Go module +You can optionally skip creating a new `go.mod` file. This is helpful when +using a monorepo setup with a shared go.mod file. When the `--skip-new-go-module` +command-line flag is supplied, the build process issues a `go get` command for +each component, relying on the Go toolchain to update the enclosing Go module appropriately. This command will avoid downgrading a dependency in the enclosing diff --git a/cmd/builder/internal/builder/main.go b/cmd/builder/internal/builder/main.go index de4a149896b..3af9fdd8775 100644 --- a/cmd/builder/internal/builder/main.go +++ b/cmd/builder/internal/builder/main.go @@ -264,6 +264,11 @@ func (c *Config) updateModules() error { } func (c *Config) updateGoModule(modspec string) error { + mod, ver, found := strings.Cut(modspec, " ") + if !found { + return fmt.Errorf("ill-formatted modspec %q: missing space separator", modspec) + } + // Re-parse the go.mod file on each iteration, since it can // change each time. modulePath, dependencyVersions, err := c.readGoModFile() @@ -271,10 +276,6 @@ func (c *Config) updateGoModule(modspec string) error { return err } - mod, ver, found := strings.Cut(modspec, " ") - if !found { - return fmt.Errorf("ill-formatted modspec %q: missing space separator", modspec) - } if mod == modulePath { // this component is part of the same module, nothing to update. return nil @@ -295,9 +296,9 @@ func (c *Config) updateGoModule(modspec string) error { } // upgrading or changing version - updatespec := mod + "@" + ver + updatespec := "-require=" + mod + "@" + ver - if _, err := runGoCommand(*c, "get", updatespec); err != nil { + if _, err := runGoCommand(*c, "mod", "edit", updatespec); err != nil { return err } return nil