go tool with isolated Go modules.
gomodtool is a wrapper around go get and go tool to install and run
tools. The difference is that gomodtool will manage each tool on its own
Go module.
Installing gomodtool itself:
go install github.com/andreynering/gomodtool@latestgomodtool get {package}@{optional-version}Examples:
# Task
gomodtool get github.com/go-task/task/v3/cmd/task@latest
# gofumpt
gomodtool get mvdan.cc/gofumpt@latest
# golangci-lint
gomodtool get github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latestgomodtool {tool} {args...}For example:
# Task
gomodtool task --list
# gofumpt
gomodtool gofumpt -w .
# golangci-lint
gomodtool golangci-lint rungomodtool will create a separate Go module for each tool you install.
These module will live in your local .gomodtool directory.
You'll see something like this:
.gomodtool/task/go.mod
.gomodtool/task/go.sum
.gomodtool/gofumpt/go.mod
.gomodtool/gofumpt/go.sum
.gomodtool/golangci-lint/go.mod
.gomodtool/golangci-lint/go.sum
go tool is really cool, but by default it adds your tools to you main module
(go.mod), and this make it bloated. It can also cause issues if you happen to
have shared dependencies between your tools and main module, specially when
they need different versions of certain packages.
Due to a limitation of go tool, the tools modules have to use the same Go
version as your main module go.mod. gomodtool handles that by creating
your tools modules with the same Go version, but if a tool needs a newer
version you might need to update your main module to follow. Also, if you
update the Go version of your main module, you might need to update the version
of all your tool modules as well.