Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: `go clean <package>` downloads modules #32977

hyangah opened this issue Jul 8, 2019 · 3 comments


Copy link

@hyangah hyangah commented Jul 8, 2019

#28680 is fixed and go clean --modcache command no longer donwloads modules before cleaning if no argument is given to the command.

Note however 'go clean' accepts packages parameter as an argument(which isn't relevant to -modcache but is still meaningful for other purposes of go clean). If they are given, go clean still downloads the modules and even updates the go.mod file.

$ go help clean
usage: go clean [clean flags] [build flags] [packages]
$ export GOPATH=$(mktemp -d)
$ go1.13beta1 clean -testcache -cache -modcache
$ go1.13beta1 mod init scratch
go: creating new go.mod: module scratch
$ go1.13beta1 clean
go: finding v0.3.2
go: downloading v0.3.2
go: extracting v0.3.2
$ cat go.mod
module scratch

go 1.13

require v0.3.2 // indirect

And the go clean -modcache <package> behaves differently.

$ go1.13beta1 clean -modcache
$ go1.13beta1 clean -modcache
go: downloading v0.3.2
go: extracting v0.3.2
go: finding v0.3.2
@hyangah hyangah added the modules label Jul 8, 2019
@bcmills bcmills added this to the Go1.14 milestone Jul 8, 2019

This comment has been minimized.

Copy link

@bcmills bcmills commented Jul 8, 2019

Probably the best we could do here is to detect that the argument to clean is not in the main module and error out.


If a package argument is given or the -i or -r flag is set, clean removes the following files from each of the source directories corresponding to the import paths: […]

But of course we cannot remove files from the (read-only) module cache.

CC @jayconrod


This comment has been minimized.

Copy link

@hitzhangjie hitzhangjie commented Sep 26, 2019

I have following project:

  • greeter
    |- go.mod: defines module a.b.c
    |- *.go

after I run go build it generates a.b.c, after I run go test it generates a.b.c.test.

But when I run go clean, a.b.c and a.b.c.test not removed, while in go 1.12.6 it works fine.


This comment has been minimized.

Copy link

@bcmills bcmills commented Sep 26, 2019

@hitzhangjie, that seems mostly unrelated to the issue reported here. If you are seeing something you believe to be a regression, please file a new issue with complete steps to reproduce it.

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.