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 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件