📦 Put dev dependencies in tools.go

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"
)
Enter fullscreen mode
Exit fullscreen mode

💡 go mod tidy doesn’t care if the package is cmd or lib

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() { // ...
}
Enter fullscreen mode
Exit fullscreen mode
// task.go
//go:build ignore package main import "github.com/arkady-emelyanov/go-shellparse" func main() { // ...
}
Enter fullscreen mode
Exit fullscreen mode

Other resources


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Privacy, cookie & data policy.