Go1.14版本vendor和gomodule冲突问题

Go1.14版本vendor和gomodule冲突问题

go1.14版本使用go mod tidy构建依赖时会出现问题(见链接), 这个问题在go1.12版本是不会出现的.

https://github.com/restic/rest-server/issues/102

这是由于1.14版本官方加入了校验机制导致的, 解答:

Hey, thanks for the hint! I'm guessing this is Go 1.14, right?

They added verification code that makes sure the vendored dependencies are in good order. You could either build without vendoring or run go mod vendor again, which will refresh everything. We will probably remove the vendored libraries, but until this is done we need to refresh them and commit the result.

Please be aware that when you do that, the Go tooling verifies that the correct code is placed into vendor/ by using the cryptographic hashes in go.sum. Pretty awesome ????

解决方法:

  1. 使用低版本的go, 但更推荐第二种方法.

  2. 删除自带vendor重建依赖

    项目文件夹下不能有vendor目录!!!, 除非是go mod vendor生成的

    # 保证在dtagentplus目录下
    # 1. 删除vendor文件夹
    mv vendor ${GOPATH}
    # 2. 重新replace本地依赖, 指向${GOPATH}/vendor
    vim go.mod
    # 3. 重建依赖
    go mod tidy
    # 4. 生成vendor, 可做可不做
    go mod vendor