【问题标题】:People can't use my v2+ semantic versioning release using gomodules人们无法使用 gomodules 使用我的 v2+ 语义版本控制版本
【发布时间】:2020-03-10 16:49:56
【问题描述】:

我正在维护一个使用Semantic Versioning 发布的公司go 库。我切换到 go modules 用于库内的依赖管理,并在 v2+ 之后创建了一个新版本。我使用了here 记录的第一个策略,其中涉及修改 go.mod 文件和导入路径。

现在当人们使用 go get 命令时(在同样使用 go 模块的 repo 中)会出现错误:

invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

有人熟悉这个问题吗?


为了让事情更简单,我创建了一个类似的简单示例:

我有包含三个文件(不包括 .gitignore)的 repo (github.com/Graphmasters/testing-gomod-versioning)。这些文件是:

  • methods/method.go
package methods

func Method() {
    println("Method")
}
  • main.go
package main

import (
    "github.com/Graphmasters/testing-gomod-versioning/v3/methods"
)

func main() {
    methods.Method()
}
  • go.mod
module github.com/Graphmasters/testing-gomod-versioning/v3

go 1.13

在 repo 中,我基于带有此代码的分支创建了一个带有标签 v3.0.0 的版本。

在使用 go modules 的 repo 中运行以下命令时遇到上述错误:

go get "github.com/Graphmasters/testing-gomod-versioning@v3.0.0"

【问题讨论】:

    标签: go semantic-versioning go-modules


    【解决方案1】:

    模块名称必须是 github.com/Graphmasters/testing-gomod-versioning/v3 或 github.com/Graphmasters/testing-gomod-versioning.v3 而不是 github.com/Graphmasters/testing-gomod-versioning

    用户应该能够使用 github.com/Graphmasters/testing-gomod-versioning/v3@v3.0.0 而不是 github.com/Graphmasters/testing-gomod-versioning@v3.0.0

    示例:可以查看以下v3包的mod文件-https://search.gocenter.io/gotest.tools~2Fv3/info?version=v3.0.0

    【讨论】:

    • 在我给出的例子中,我已经有了 github.com/Graphmasters/testing-gomod-versioning/v3。使用go get github.com/Graphmasters/testing-gomod-versioning/v3@v3.0.0没有用,虽然go get github.com/Graphmasters/testing-gomod-versioning/v3 用了,但我们需要特定的版本。我通过下载 github.com/olivere/elastic 的特定版本进行了检查,并且该版本有效,因此尚不清楚在这种情况下出现了什么问题。
    • 好的,谢谢。在最初提供的示例中,go get 示例中缺少 v3 后缀,因此不确定。 v3.0.0 标签是使用 go.mod 创建的,引用 github.com/Graphmasters/testing-gomod-versioning/v3 作为模块名称吗?什么错误?
    猜你喜欢
    • 2018-08-08
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 2017-11-04
    • 2017-06-01
    • 2020-03-27
    • 2015-10-28
    相关资源
    最近更新 更多