小编N N*_*N N的帖子

当顶级模块及其子模块之一作为单独的版本单独导入时,如何解决冲突的 go 模块依赖项?

我的项目中有两个依赖项。

go.mod

module github.com/test-org/test-repo

go 1.12

require (
    github.com/foo/bar v1.0.0
    github.com/raz/mataz v1.0.0
)
Run Code Online (Sandbox Code Playgroud)

运行后go mod download,这两个依赖项导致github.com/shared/dependency要下载两个不同版本的 a 。有趣的是github.com/shared/dependency包含子模块,例如:

dependency
  -- go.mod
  -- api
      -- go.mod
Run Code Online (Sandbox Code Playgroud)

检查下载的模块显示两个版本已下载到我的本地机器:

ls ${GOPATH}/pkg/mod/github.com/shared

[dir] dependency    [dir] dependency@v1.1.0
Run Code Online (Sandbox Code Playgroud)

ls ${GOPATH}/pkg/mod/github.com/shared/dependency

[dir] api@v1.2.0
Run Code Online (Sandbox Code Playgroud)

查看这些目录的内容:

${GOPATH}/pkg/mod/github.com/shared/dependency@v1.1.0

v1.1.0 中整个 repo 的文件内容,包括api带有自己go.mod文件的文件夹。

${GOPATH}/pkg/mod/github.com/shared/dependency/api@v1.2.0

apiv1.2.0中repo所在文件夹的文件内容,包括go.mod文件。


最后,我的.go文件中test-repo有以下设置:

package test-package

import (
    "github.com/foo/bar"
)

func MyFunc() {...bar.NewBar()...}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行MyFunc(存在于其他地方)的测试时,我收到一条unknown …

dependencies go dependency-management go-modules

6
推荐指数
1
解决办法
6522
查看次数