DEV Community

Jacob Hummer
Jacob Hummer

Posted on • Edited on • Originally published at jcbhmr.me

Put dev dependencies in tools.go

Problem: You have a ./gen.go script that uses github.com/arkady-emelyanov/go-shellparse to do some stuff. When you run go mod tidy it removes github.com/arkady-emelyanov/go-shellparse from your go.mod because ./gen.go has a //go:build ignore in it... which means go mod tidy doesn't include it in its checks. 😔

gen.go

//go:build ignore

package main

import (
    "github.com/arkady-emelyanov/go-shellparse"
    // etc.
)

func main() {
    shellparse.ParseVarsFile("file.txt")
    exec.Command("go", "run", "github.com/melbahja/got/cmd/got").Run()
}
Enter fullscreen mode Exit fullscreen mode

Solution: Use tools.go with //go:build tools which go mod tidy does scan and add any dependencies to list all the dependencies that ./gen.go needs.

tools.go

//go:build tools

package tools

import (
    _ "github.com/melbahja/got/cmd/got"
    _ "github.com/arkady-emelyanov/go-shellparse"
    // etc.
)
Enter fullscreen mode Exit fullscreen mode
go run ./gen.go
Enter fullscreen mode Exit fullscreen mode

Further reading 📚

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay