dtsps2098 2018-11-26 00:10
浏览 580
已采纳

go.mod文件中的exclude指令如何工作?

The new Go version 1.11 introduced the modules concept which is awesome.

In the documentation it says there are four directives that can be used in a go.mod file: module, require, exclude, replace.

It also explains that:

exclude and replace directives only operate on the current (“main”) module. exclude and replace directives in modules other than the main module are ignored when building the main module. The replace and exclude statements therefore allow the main module complete control over its own build, without also being subject to complete control by dependencies.

But I still don't understand how the exclude directive works.

Can someone explain to me how the exclude directive works and if possible give an example of when to use it?

  • 写回答

2条回答 默认 最新

  • douluoxiao2286 2018-12-17 22:40
    关注

    Here's a semi-hypothetical hypothetical example:

    go.mod

    module github.com/example/project
    
    require (
        github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc
        github.com/google/uuid v1.1.0
    )
    
    exclude github.com/SermoDigital/jose v0.9.1
    
    replace github.com/google/uuid v1.1.0 => git.coolaj86.com/coolaj86/uuid.go v1.1.1
    

    exclude

    In the case of the github.com/SermoDigital/jose package, it has a proper git tag for v0.9.1, but the current version is v1.1, which is NOT a proper git tag (missing the "patch" version).

    By excluding the broken version it causes go mod to fetch from master instead.

    replace

    Likewise (and truly hypothetical), if I have a patch to github.com/google/uuid, I can create a fork and use replace to get my own version while I wait for the upstream version to accept my patch (or not).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?