Skip to content

cmd/go: 'go mod download' pulls in test dependencies of dependencies #41431

@prashantv

Description

@prashantv

What version of Go are you using (go version)?

$ go version
go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/prashant/.cache/go-build"
GOENV="/home/prashant/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/prashant/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/prashant/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/prashant/.gimme/versions/go1.15.2.linux.amd64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/prashant/.gimme/versions/go1.15.2.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/prashant/go/src/github.com/prashantv/go-mod-download-repro/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build327180583=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go mod download for a module (called go-mod-download-repro in the example) that takes on a dependency on another module (go.uber.org/atomic in the example), which only has external dependencies in tests.

go.mod:

module github.com/prashantv/go-mod-download-repro

go 1.14

require go.uber.org/atomic v1.7.0

main.go:

package main

import (
        "fmt"

        "go.uber.org/atomic"
)

func main() {
        var i atomic.Int32
        i.Inc()
        fmt.Println(i.Load())
}

go.uber.org/atomic has test dependencies on testify.

Download to a local directory to see what is downloaded: $ GOMODCACHE=$(pwd)/cache go mod download

What did you expect to see?

Expected to see all dependencies of go-mod-download-repro to be downloaded, but not the test dependencies of go.uber.org/atomic.

What did you see instead?

Only dependenceis required to build/test go-mod-download-repro.

If this behaviour is intentional, would it be possible to add an option to limit the download to just packages needed to build, or to packages needed to test the current module?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions