Trace minimal version selection
Trace minimal version selection
Minimal version selection (MVS) chooses, for each module path, the highest version required in the relevant module requirement graph. It does not automatically choose the newest published release. A require directive is a minimum, not an upper bound. Distinct major-version paths are separate identities.
Use a fresh directory for each example, create the listed files (labels are not file contents), and run the commands in a POSIX shell. Use Go 1.23+, local toolchain, and Python 3 only for the synthetic proxy examples. For isolation, set GOWORK=off, GOTOOLCHAIN=local, GOPROXY=off and GOSUMDB=off for these local labs only; use a fresh GOMODCACHE per lab. Proxy examples override GOPROXY to a local file URL. Do not copy disabled checksum settings to real projects.
--- proxy.py ---from pathlib import Pathimport json, zipfileroot=Path("proxy")for version in ("v1.0.0", "v1.1.0", "v1.2.0", "v1.3.0", "v1.2.1-0.20240102030405-abcdef123456"): path="example.test/lib" d=root/path/"@v"; d.mkdir(parents=True,exist_ok=True) mod="module "+path+"\n\ngo 1.23.0\n" if version=="v1.3.0": mod+="\nretract v1.2.0 // demonstration\n" (d/(version+".mod")).write_text(mod) (d/(version+".info")).write_text(json.dumps({"Version":version,"Time":"2024-01-02T03:04:05Z"})) with zipfile.ZipFile(d/(version+".zip"),"w") as z: prefix=path+"@"+version+"/" z.writestr(prefix+"go.mod",mod) z.writestr(prefix+"lib.go",'package lib\nfunc Version() string { return "'+version+'" }\n') (d/"list").write_text("v1.0.0\nv1.1.0\nv1.2.0\nv1.3.0\n")
--- go.mod ---module example.test/app
go 1.23.0
require ( example.test/lib v1.0.0 example.test/feature v1.0.0)replace example.test/feature => ./feature
--- main.go ---package main
import ( "example.test/feature" "example.test/lib" "fmt")
func main() { fmt.Println(lib.Version(), feature.Version()) }
--- feature/go.mod ---module example.test/feature
go 1.23.0
require example.test/lib v1.1.0
--- feature/feature.go ---package feature
import "example.test/lib"
func Version() string { return lib.Version() }
--- Commands (shell, from project root) ---python3 proxy.pyexport GOPROXY="file://$PWD/proxy" GOSUMDB=off GONOSUMDB=none GOPRIVATE= GONOPROXY=nonego mod tidygo list -m -f '{{.Version}}' example.test/libgo run .The app requires v1.0.0 while feature requires v1.1.0. Both import paths resolve to v1.1.0. A newer v1.3.0 exists in the proxy but is not selected by this graph. tidy updates the main module requirements to reflect the loaded packages.
Expected output:
v1.1.0v1.1.0 v1.1.0Raise the direct minimum
--- proxy.py ---from pathlib import Pathimport json, zipfileroot=Path("proxy")for version in ("v1.0.0", "v1.1.0", "v1.2.0", "v1.3.0", "v1.2.1-0.20240102030405-abcdef123456"): path="example.test/lib" d=root/path/"@v"; d.mkdir(parents=True,exist_ok=True) mod="module "+path+"\n\ngo 1.23.0\n" if version=="v1.3.0": mod+="\nretract v1.2.0 // demonstration\n" (d/(version+".mod")).write_text(mod) (d/(version+".info")).write_text(json.dumps({"Version":version,"Time":"2024-01-02T03:04:05Z"})) with zipfile.ZipFile(d/(version+".zip"),"w") as z: prefix=path+"@"+version+"/" z.writestr(prefix+"go.mod",mod) z.writestr(prefix+"lib.go",'package lib\nfunc Version() string { return "'+version+'" }\n') (d/"list").write_text("v1.0.0\nv1.1.0\nv1.2.0\nv1.3.0\n")
--- go.mod ---module example.test/app
go 1.23.0
require ( example.test/lib v1.3.0 example.test/feature v1.0.0)replace example.test/feature => ./feature
--- main.go ---package main
import ( "example.test/feature" "example.test/lib" "fmt")
func main() { fmt.Println(lib.Version(), feature.Version()) }
--- feature/go.mod ---module example.test/feature
go 1.23.0
require example.test/lib v1.1.0
--- feature/feature.go ---package feature
import "example.test/lib"
func Version() string { return lib.Version() }
--- Commands (shell, from project root) ---python3 proxy.pyexport GOPROXY="file://$PWD/proxy" GOSUMDB=off GONOSUMDB=none GOPRIVATE= GONOPROXY=nonego mod tidygo list -m -f '{{.Version}}' example.test/libgo run .Now the main module requires the higher version. The local feature replacement is only a way to make the transitive requirement visible offline. Its own requirements still participate in selection.
Expected output:
v1.3.0v1.3.0 v1.3.0Try it locally
Change the feature requirement to v1.3.0 and the direct requirement to v1.0.0. Print the chosen version after tidy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Modules and workspaces 04: Trace minimal version selection
Check the lesson objective before moving on.
Which version wins if dependencies require v1.0.0 and v1.1.0 of the same path?
Does MVS fetch the newest version just because it exists?