go build一直抱怨:go.mod具有post-v0模块路径 [英] go build keeps complaining that: go.mod has post-v0 module path

查看:548
本文介绍了go build一直抱怨:go.mod具有post-v0模块路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Go 1.11发行之后,我一直试图通过在其根目录中添加go.mod文件将存储库移至Go模块.

Following the release of Go 1.11, I have been trying to move my repositories to Go modules, by adding a go.mod file at their root.

我的一个根库my.host/root的版本为17.0.1,因此我在其go.mod文件中编写了该文件:

One of my root libraries my.host/root is in its version 17.0.1, so I wrote in its go.mod file:

module my.host/root/v17

我标记了Go模块手册中记录的版本v17.0.1.

I tagged that version v17.0.1 as documented in the Go modules manual.

当我尝试创建一个使用我的根库的新Go项目时,例如:

When I try to make a new Go project that uses my root library, like:

package main

import root "my.host/root/v17"

func main() {
    root.DoSomething()
}

并尝试对其进行编译,出现以下错误:

And try to compile it, I get the following error:

go:my.host/root@v0.0.0-20180828034419-6bc78016491a:go.mod在修订版6bc78016491a中具有后v0模块路径"my.host/root/v17"

go: my.host/root@v0.0.0-20180828034419-6bc78016491a: go.mod has post-v0 module path "my.host/root/v17" at revision 6bc78016491a

我不知所措,想知道为什么会这样.我在go.mod文件中明确添加了v17.0.1,但是每次尝试都会用v0.0.0-20180828034419-6bc78016491a版本替换该条目,然后该版本失败,因为在该提交时,我的根库中的go.mod文件module条目确实以v17结尾.

I am at loss figuring out why this happens. I explicitly added v17.0.1 in the go.mod file, yet every attempt at go build replaces the entry with a v0.0.0-20180828034419-6bc78016491a version which then fails because at that commit, the go.mod file module entry of my root library indeed ends with a v17, as it should.

作为记录,此提交与标记的v17.0.1版本相同.

For the record, this commit is the same as the tagged v17.0.1 version.

我在这里做错了什么?我该如何调试这种情况?

What am I doing wrong here? How can I debug this situation?

推荐答案

我犯了两个错误:

  • 我最初的v17.0.0标记将指向go.mod不包含v17导入路径后缀的提交.结果,Go工具似乎将整个v17主版本视为v0/v1,即使以后的v17标签指向具有正确go.mod指令的提交,也是如此,因此,提交ID为翻译".
  • 在我的从属项目的go.mod文件中,我错误地指定了
    require my.host/root v17.0.1代替
    require my.host/root/v17 v17.0.1.
  • My initial v17.0.0 tag would point to a commit where go.mod did not contain the v17 import path suffix. As a result, it seems Go tooling considers the whole v17 major version as a v0/v1 instead, even if later v17 tags point to a commit with a correct go.mod directive, hence the commit ID "translation".
  • In my dependent projects, in the go.mod file, I mistakenly specified
    require my.host/root v17.0.1 instead of
    require my.host/root/v17 v17.0.1.

在解决了这两个问题之后,一切似乎都恢复了正常,并且运行良好.我希望文档对此有所了解,但是我想这是一个做出贡献的好机会!

After fixing both those issues, everything seems back to normal and it works perfectly. I wish the documentation had been clearer about this but I guess this is a good opportunity to make a contribution!

这篇关于go build一直抱怨:go.mod具有post-v0模块路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆