go version)?$ go version go version go1.11 darwin/amd64
Yes
go env)?go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/aj/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/aj/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/aj/github.com/xxx/xxx/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0g/01vpdjf507z8qk3lvgfnh1hw0000gn/T/go-build639981897=/tmp/go-build -gno-record-gcc-switches -fno-common"
I have a module which is not a code dependency, but rather a go generate dependency:
//go:generate go run github.com/UnnoTed/fileb0x b0x.toml
I'm trying to add it to my vendor directory and have it stay there.
I'd expect to be able to run go mod vendor and have the generate dependencies copied over as well.
Even though I've manually added the go generate dependency into go.mod it's not it's not being copied to vendor when I run go mod vendor. In fact, it's sometimes pruned from vendor when I run that.
See https://github.com/golang/go/issues/25922 and https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module. go mod generally removes (prunes) unused dependencies, so right now you need to keem them as imports somewhere.
@mvdan Thanks for the quick reply. It's a binary, not a library, so it's not possible even to use _ to import and ignore. Any other ideas?
For the benefit of others:
tools/tools.go:
// +build tools
// tools is a dummy package that will be ignored for builds, but included for dependencies
package tools
import (
_ "example.com/foo/thing"
)
go mod tidy
This will cause the utilities to be included in go.mod and with go mod vendor (after a go mod tidy or other command that causes deps to re-evaluate), but they will not be checked (i.e. a binary can be included as a dependency, which is not allowed for a build).
For more details see https://stackoverflow.com/a/54028731/151312
Update: Using +build tools rather than +build ignore, which has a distinct meaning (and is ignored by go mod tidy).
Also, you should append -mod vendor to all go commands:
go generate -mod vendor ./...
//go:generate go run -mod vendor example.com/thing
go build -mod vendor
Most helpful comment
For the benefit of others:
tools/tools.go:This will cause the utilities to be included in
go.modand withgo mod vendor(after ago mod tidyor other command that causes deps to re-evaluate), but they will not be checked (i.e. a binary can be included as a dependency, which is not allowed for a build).For more details see https://stackoverflow.com/a/54028731/151312
Update: Using
+build toolsrather than+build ignore, which has a distinct meaning (and is ignored bygo mod tidy).Also, you should append
-mod vendorto all go commands: