2018-10-23 11:44
浏览 584

在运行测试之前,如何自动清除Visual Code中的go缓存?

There is a small nuisance with Visual Code and Go, but is mainly related to the most recent release of go 1.11.x and the newly introduced module system. The go builder creates a folder called 'auto' for cached builds, which can be cleaned / deleted via 'go clean -cache'.

Visual Code seems to be confused when executing tests, if such a directory is present, and complains about missing dependencies:

/home/user/.golang/src/ could not import (open auto/4c/4cb1f0f2c9f328e3cade99998704759897fd4e530af38db25c85cdc253c1f1a0-d: no such file or directory)

is there any possibility to fix this? Or is it just another setting I forgot to make?

图片转代码服务由CSDN问答提供 功能建议

Visual Code和Go有点麻烦,但主要与go 1.11的最新版本有关。 x和新引入的模块系统。 go构建器为缓存的构建创建了一个名为“ auto”的文件夹,可以通过“ go clean -cache”来清除/删除该文件夹。

执行测试时,如果存在这样的目录,Visual Code似乎会感到困惑,并且抱怨缺少依赖项:

  / home  /user/.golang/src/无法导入 auto / 4c / 4cb1f0f2c9f328e3cade99998704759759fd4e530af38db25c85cdc253c1f1a 没有此类文件或目录)

是否有可能解决此问题? 还是只是我忘记做的另一种设置?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doujianwei8217 2018-10-23 12:32

    Try setting the environment variable GOCACHE=off.

    打赏 评论
  • doushi6947 2019-01-12 23:24

    Warning from issue 26809 ("GOCACHE=off causes modules to exit the tests"):

    The GOCACHE env variable will be phased out out in 1.12, and cannot be used with go modules enabled in 1.11

    Configuring VSCode to use using go test -count=1 ... is safer.

    The Go 1.12 release notes (for February 2019) makes that official:

    Build cache requirement

    The build cache is now required as a step toward eliminating $GOPATH/pkg.
    Setting the environment variable GOCACHE=off will cause go commands that write to the cache to fail.

    打赏 评论

相关推荐 更多相似问题