首页 > 解决方案 > go.mod 替换指令被忽略

问题描述

我正在使用来自 Apache 的 Go thrift 包,它位于lib/go/thriftGit 存储库中git.apache.org/thrift.git。这是导入语句:

import "git.apache.org/thrift.git/lib/go/thrift"

这适用于使用官方 Apache 代码,但我们需要对 Apache 代码进行更改,所以我只是在go.mod文件中添加了一个替换指令,以便项目获取我们更改后的包版本:

replace git.apache.org/thrift.git/lib/go/thrift => <local_path>/lib/go/thrift

<local_path>(修补的)git repo 的保存位置在哪里。我go.mod在这个位置 ( ) 添加了一个文件,<local_path>/lib/go/thrift其中仅包含以下内容:

module git.apache.org/thrift.git/lib/go/thrift

go 1.12

然而 Go 编译器 ( $ go build) 坚持下载和使用 Apache 包并且忽略了该replace指令。关于这个问题的原因有什么想法吗?

标签: gomodule

解决方案


我发现的解决方法(经过大量试验)是go.mod<local_path>/lib/go/thrift(这一步是必不可少的)中删除文件并将此go.mod文件添加到<local_path>

module git.apache.org/thrift.git

go 1.12

另外还要更改replace指令以删除这样的lib/go/thrift部分:

replace git.apache.org/thrift.git => <local_path>

进口声明没有改变。


推荐阅读