简体   繁体   English

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

[英]How to get dep ensure to remove unused Go files, dependencies or packages

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. 使用dep ensure -add <package>添加新的依赖项时,请dep ensure -add <package>我看到dep添加了软件包的完整存储库,而不仅仅是我需要的部分。

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. 例如,即使我仅使用AWS Secrets Manager服务,我也添加了aws-sdk-godep ensure将87MB的文件放入我的供应商文件夹中。

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/. 要解决此问题,您需要定义[prune]设置,这些设置确定哪些文件和目录可以被认为是不必要的,并因此自动从供应商/中删除。

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 unused-packages表示应删除未出现在软件包导入图中的目录中的文件
  • non-go prunes files that are not used by Go Go不使用的non-go修剪文件
  • go-tests prunes Go test files go-tests李子去测试文件

Out of an abundance of caution, dep non-optionally preserves files that may have legal significance. 出于谨慎考虑,dep会非强制性地保留可能具有法律意义的文件。

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. 但是,通过dep init生成Gopkg.toml将添加行以在根级别启用go-testsunused-packages修剪选项。

[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. 需要一个附加的名称字段,并且与[[constraint]][[override]] ,应该是源根目录 ,而不仅仅是任何导入路径。

[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. 通常,也可以安全地设置non-go = true 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. 但是,由于dep仅具有Go文件所扮演角色的清晰模型,而非Go文件必然不在该模型范围内,因此没有可比的安全性一般定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM