Introduction
Go modules, introduced in Go 1.11, provide dependency management for Go projects. Besides runtime dependencies, users may need to utilize go modules during the build process, specifically for tools that run during the go generate command.
Question
How can I incorporate a specific build dependency, such as github.com/aprice/embed/cmd/embed, and execute it from a specific directory? Is go get the appropriate tool for this task?
Answer
Using the following methods, you can embed a command dependency in Go modules:
Creating a "Tools" Package
Create a tools directory within your project:
mkdir -p internal/tools
// internal/tools/tools.go // +build tools package tools import ( _ "github.com/UnnoTed/fileb0x" )
Updating go.mod
Vendoring
Additional Notes
The above is the detailed content of How to Embed a Build-Time Command Dependency (e.g., `github.com/aprice/embed/cmd/embed`) in Go Modules?. For more information, please follow other related articles on the PHP Chinese website!