duancong6937 2018-10-02 01:30
浏览 39
已采纳

扁平化主要依赖的供应商可传递依赖

I have been converting existing projects from using vendored dependencies via Glide, to using the Go 1.11.x module support. But I am hitting a particular case in one project using modules that I cannot solve.

Internal project 'foo' has its dependencies vendored via "go mod vendor":

projects/src/foo/
    main.go
    vendor/
        ...

This works great when building that project internally since a non-go developer can clone the project to any location and build it, with no external proxy access needed to download dependencies.

Now I am trying to allow project 'bar' to build a tool using library 'foo'.

package bar

import "internal.com/project/foo"

The "go.mod" file only contains:

module internal.com/project/bar

require internal.com/project/foo v0.0.0-...

I would vendor via:

go module vendor

And I build via:

go build -mod=vendor

What I am seeing is that 'foo' will be cloned from the internal git repo, and all of its dependencies will be downloaded from their remote git origins, and my 'go.sum' file is updated with all of the transient dependencies. But what I really want is to only fetch 'foo' from my internal network and to have it flatten the vendored dependencies. Ideally, there should be no external http requests.

Is this even possible? The "-mod=vendor" flag was very useful when building project "foo" directly. But it doesn't seem to apply here because project "bar" doesn't want to vendor. It wants to get the one primary dependency and that is it. It would seem that Go module support doesn't care about flattening vendored transient dependencies.

Previous when using glide as the package manager, it would fetch 'foo' from the internal git repo and then flatten all of its dependencies into my vendor directory.

Originally posted as a question to golang-nuts, without reply.

  • 写回答

1条回答 默认 最新

  • dsoxcj7276 2018-10-06 08:28
    关注

    It just currently doesn't work that way, only the top level vendor directory is used. From the modules help:

    To build using the main module's top-level vendor directory to satisfy dependencies (disabling use of the usual network sources and local caches), use 'go build -mod=vendor'. Note that only the main module's top-level vendor directory is used; vendor directories in other locations are still ignored.

    For this specific use case I would recommend waiting until go modules matures.

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

报告相同问题?

悬赏问题

  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Linux权限管理相关操作(求解答)
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
  • ¥15 android 打包报错