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

Go mod file has multiple require blocks with mixed indirect and direct deps #755

Closed
shahzadlone opened this issue Aug 23, 2022 · 0 comments · Fixed by #756
Closed

Go mod file has multiple require blocks with mixed indirect and direct deps #755

shahzadlone opened this issue Aug 23, 2022 · 0 comments · Fixed by #756
Assignees
Labels
ci/build This is issue is about the build or CI system, and the administration of it. dependencies Related to dependencies todo 🗒️

Comments

@shahzadlone
Copy link
Member

Go mod file has multiple require blocks with mixed indirect and direct dependencies.

Since go1.17 it makes a distinction between the separating/grouping direct and indirect require blocks.

More info: https://go.dev/doc/go1.17#go-command

Pruned module graphs in go 1.17 modules

If a module specifies go 1.17 or higher, the module graph includes only the immediate dependencies of other go 1.17 modules, not their full transitive dependencies. (See Module graph pruning for more detail.)

For the go command to correctly resolve transitive imports using the pruned module graph, the go.mod file for each module needs to include more detail about the transitive dependencies relevant to that module. If a module specifies go 1.17 or higher in its go.mod file, its go.mod file now contains an explicit require directive for every module that provides a transitively-imported package. (In previous versions, the go.mod file typically only included explicit requirements for directly-imported packages.)

Since the expanded go.mod file needed for module graph pruning includes all of the dependencies needed to load the imports of any package in the main module, if the main module specifies go 1.17 or higher the go tool no longer reads (or even downloads) go.mod files for dependencies if they are not needed in order to complete the requested command. (See Lazy loading.)

Because the number of explicit requirements may be substantially larger in an expanded Go 1.17 go.mod file, the newly-added requirements on indirect dependencies in a go 1.17 module are maintained in a separate require block from the block containing direct dependencies.

To facilitate the upgrade to Go 1.17 pruned module graphs, the go mod tidy subcommand now supports a -go flag to set or change the go version in the go.mod file. To convert the go.mod file for an existing module to Go 1.17 without changing the selected versions of its dependencies, run:

  go mod tidy -go=1.17

By default, go mod tidy verifies that the selected versions of dependencies relevant to the main module are the same versions that would be used by the prior Go release (Go 1.16 for a module that specifies go 1.17), and preserves the go.sum entries needed by that release even for dependencies that are not normally needed by other commands.

The -compat flag allows that version to be overridden to support older (or only newer) versions, up to the version specified by the go directive in the go.mod file. To tidy a go 1.17 module for Go 1.17 only, without saving checksums for (or checking for consistency with) Go 1.16:

  go mod tidy -compat=1.17

Note that even if the main module is tidied with -compat=1.17, users who require the module from a go 1.16 or earlier module will still be able to use it, provided that the packages use only compatible language and library features.

The go mod graph subcommand also supports the -go flag, which causes it to report the graph as seen by the indicated Go version, showing dependencies that may otherwise be pruned out.

@shahzadlone shahzadlone added todo 🗒️ ci/build This is issue is about the build or CI system, and the administration of it. dependencies Related to dependencies labels Aug 23, 2022
@shahzadlone shahzadlone added this to the DefraDB v0.3.1 milestone Aug 23, 2022
@shahzadlone shahzadlone self-assigned this Aug 23, 2022
shahzadlone added a commit that referenced this issue Aug 23, 2022
- Resolves #755

- Description: Cleans up `go.mod` file according to go1.17 changes. Rather than having 3 blocks of mixed dependencies, now we have 2 blocks where one contains direct dependencies and one contains indirect ones.
shahzadlone added a commit to shahzadlone/defradb that referenced this issue Feb 23, 2024
- Resolves sourcenetwork#755

- Description: Cleans up `go.mod` file according to go1.17 changes. Rather than having 3 blocks of mixed dependencies, now we have 2 blocks where one contains direct dependencies and one contains indirect ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build This is issue is about the build or CI system, and the administration of it. dependencies Related to dependencies todo 🗒️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant