doujichan1399 2018-12-04 06:08
浏览 182
已采纳

如何获取Dep确保删除未使用的Go文件,依赖项或软件包

When adding new dependencies using dep ensure -add <package> I see dep adding the complete repository of the package, instead of just the parts I require.

For example I added aws-sdk-go and dep ensure put 87MB of files into my vendors folder, even though I only use the AWS Secrets Manager service.

  • 写回答

1条回答 默认 最新

  • dsgixl5195 2018-12-04 06:08
    关注

    To resolve this you need to define [prune] settings which determine what files and directories can be deemed unnecessary, and thus automatically removed from vendor/.

    The following options are currently available:

    • unused-packages indicates that files from directories that do not appear in the package import graph should be pruned
    • non-go prunes files that are not used by Go
    • go-tests prunes Go test files

    Out of an abundance of caution, dep non-optionally preserves files that may have legal significance.

    Pruning options are disabled by default. However, generating a Gopkg.toml via dep init will add lines to enable go-tests and unused-packages prune options at the root level.

    [prune]
      go-tests = true
      unused-packages = true
    

    The same prune options can be defined per-project. An additional name field is required and, as with [[constraint]] and [[override]], should be a source root, not just any import path.

    [prune]
      non-go = true
    
      [[prune.project]]
        name = "github.com/project/name"
        go-tests = true
        non-go = false
    

    Almost all projects will be fine without setting any project-specific rules, and enabling the following pruning rules globally:

    [prune]
      unused-packages = true
      go-tests = true
    

    It is usually safe to set non-go = true, as well. However, as dep only has a clear model for the role played by Go files, and non-Go files necessarily fall outside that model, there can be no comparable general definition of safety.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题