go - go.mod 替换指令被忽略
问题描述
我正在使用来自 Apache 的 Go thrift 包,它位于lib/go/thrift
Git 存储库中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
指令。关于这个问题的原因有什么想法吗?
解决方案
我发现的解决方法(经过大量试验)是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>
进口声明没有改变。
推荐阅读
- detox - 使用 detox 和 IOS 时如何返回?
- firebase - 使用firebase auth和firebase核心依赖后出现flutter firebase版本解决错误
- javascript - 自动检测字体形式 PDF。下载字体并在网站上以该字体显示文本?
- excel - 使用 VBA 的 Ultimate 1000 分隔符
- r - 为什么我无法更改此 sf 对象绘图的图例标题?
- azure - 如何使用 REST API 在经典发布管道中使用手动干预任务获取批准者详细信息
- android - 无法启动 AVD
- r - 阅读 R 中的 Sqlite 视图定义
- c# - 碰撞后如何为我的玩家关闭重力?
- python - 努力理解这个while循环