具有相同依赖项的两个版本-较低版本被忽略 [英] Two version of same dependency - lower version getting ignored

查看:303
本文介绍了具有相同依赖项的两个版本-较低版本被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中两个依赖项使用同一库的不同版本.例如,我的项目具有依赖项A和依赖项B. AB都使用公共库/依赖项X,但版本不同. A具有Xv1版本,B具有Xv2版本.所以现在当我添加A& B作为我项目中的依赖项,我项目的go.sum中有X个版本.

I have a project in which two dependencies uses different version of same library. For instance, my project has dependency A and dependency B. A and B, both uses a common library/dependency X, but of different versions. A has v1 version of X and B has v2 version of X. So now when I add A & B as dependencies in my project, there are 2 versions of X in my project's go.sum.

我期望,各个版本将在运行时由AB引用.但事实并非如此.当我在项目上运行测试时,A使用的是Xv2,理想情况下,它应该使用v1(因为在Ago.mod中,已明确指定/添加了v1).这样会中断执行,因为Xv1v2之间存在很多差异.

I was expecting, the respective versions will be referred at run time by A and B. But it is not the case. Somehow when I run tests on my project, the A is using v2 of X, ideally it should use v1 (because in go.mod of A, explicitly specified/added v1). So it breaks the execution,because there are lot differences in v1 and v2 of X.

因此,在我的项目中,如何明确指定使用A使用Xv1并使用B使用v2? Go模块中有这样的规定吗?

So in my project, how can I explicitly specify that to use v1 of X by A and use v2 by B? Is there such provision in go modules?

推荐答案

您的B软件包必须导入带有/v2后缀的X.

Your B package must import X with a /v2 suffix.

转到Wiki:模块:语义导入版本控制:

当v1或更高版本的程序包进行向后不兼容的更改时,请回想 semver ,需要对版本进行重大更改.遵循导入兼容性规则和semver的结果称为语义导入版本控制,其中主要版本包含在导入路径中–这可确保在主要版本由于破坏兼容性.

Recall semver requires a major version change when a v1 or higher package makes a backwards incompatible change. The result of following both the import compatibility rule and semver is called Semantic Import Versioning, where the major version is included in the import path — this ensures the import path changes any time the major version increments due to a break in compatibility.

由于语义导入版本控制,选择加入Go模块的代码必须遵守以下规则:

As a result of Semantic Import Versioning, code opting in to Go modules must comply with these rules:

  • 如果模块的版本为v2或更高版本,则必须在go.mod文件(例如,module github.com/my/mod/v2require github.com/my/mod/v2 v2.0.0)中使用的模块路径末尾将模块的主版本作为/vN包括在内.并在包导入路径中(例如import "github.com/my/mod/v2/mypkg").
  • If the module is version v2 or higher, the major version of the module must be included as a /vN at the end of the module paths used in go.mod files (e.g., module github.com/my/mod/v2, require github.com/my/mod/v2 v2.0.0) and in the package import path (e.g., import "github.com/my/mod/v2/mypkg").

导入路径中的此版本后缀将使它们成为2个不同"的软件包.如果AB使用X的相同主版本,则将没有2个主版本,则将选择较高的版本(最小版本选择"算法).有关详细信息,请参见版本选择.

This version suffix in the import path will make them 2 "different" packages. If A and B would use the same major version of X, then there would be no 2 versions of it, the higher version would be chosen ("minimal version selection" algorithm). For details, see Version Selection.

这篇关于具有相同依赖项的两个版本-较低版本被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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