[英]Two version of same dependency - lower version getting ignored
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
和依赖项B
A
and B
, both uses a common library/dependency X
, but of different versions. A
和B
都使用公共库/依赖项X
,但版本不同。 A
has v1
version of X
and B
has v2
version of X
. A
具有X
v1
版本,而B
具有X
v2
版本。 So now when I add A
& B
as dependencies in my project, there are 2 versions of X
in my project's go.sum
. 所以现在当我在项目中添加
A
和B
作为依赖项时,项目go.sum
有两个X
版本。
I was expecting, the respective versions will be referred at run time by A
and B
. 我期望在运行时由
A
和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
). 不知何故,当我在项目上运行测试时,
A
正在使用X
v2
,理想情况下,它应该使用v1
(因为A
go.mod
中已明确指定/添加了v1
)。 So it breaks the execution,because there are lot differences in v1
and v2
of X
. 由于
X
v1
和v2
存在很多差异,因此它会中断执行。
So in my project, how can I explicitly specify that to use v1
of X
by A
and use v2
by B
? 因此,在我的项目中,如何明确指定使用
A
的X
的v1
和B
v2
? Is there such provision in go modules? go模块中是否有此类规定?
Your B
package must import X
with a /v2
suffix. 您的
B
软件包必须导入带有/v2
后缀的X
Go Wiki: Modules: Semantic Import versioning: 转到Wiki:模块:语义导入版本控制:
Recall semver requires a major version change when a v1 or higher package makes a backwards incompatible change.
当v1或更高版本的软件包进行向后不兼容的更改时,召回semver需要对主要版本进行更改。 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.
遵循导入兼容性规则和semver的结果称为语义导入版本控制 ( Semantic Import Versioning) ,其中主要版本包含在导入路径中-这可确保在主要版本由于兼容性中断而增加时,导入路径会随时更改。
As a result of Semantic Import Versioning, code opting in to Go modules must comply with these rules:
语义导入版本控制的结果是,加入Go模块的代码必须遵守以下规则:
- 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 (eg,module github.com/my/mod/v2
,require github.com/my/mod/v2 v2.0.0
) and in the package import path (eg,import "github.com/my/mod/v2/mypkg"
).如果模块是版本V2或更高,该模块的主版本必须被包括作为
/vN
在模块路径的在go.mod文件(例如,所使用的端module github.com/my/mod/v2
,require github.com/my/mod/v2 v2.0.0
)并在包导入路径中(例如,import "github.com/my/mod/v2/mypkg"
)。
This version suffix in the import path will make them 2 "different" packages. 导入路径中的此版本后缀将使它们成为2个“不同”的软件包。 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). 如果
A
和B
使用X
的相同主版本,则将没有2个主版本,则将选择较高的版本(“最小版本选择”算法)。 For details, see Version Selection . 有关详细信息,请参见版本选择 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.