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 📚

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

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

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay