TL;DR: Use a tools.go file with //go:build tools to list import _ “github.com/octocat/somedevtool” to stop go mod tidy from removing them.
//go:build tools
package tools
import (
_ “github.com/melbahja/got/cmd/got”
_ “github.com/arkady-emelyanov/go-shellparse”
)
💡 go mod tidy works with cmd packages too
Then you can use whatever you list in tools.go in //go:generate and task.go!
//go:generate -command got go run github.com/melbahja/got/cmd/got
package main
import “fmt”
//go:generate got https://example.org/
func main() {
// …
}
// task.go
//go:build ignore
//go:build ignore
package main
import “github.com/arkady-emelyanov/go-shellparse”
func main() {
// …
}
Other resources
https://play-with-go.dev/tools-as-dependencies_go119_en/
https://www.tiredsg.dev/blog/golang-tools-as-dependencies/