行家;如何打破向后兼容性?
Maven 有一个版本管理系统,如果引用多个版本,该系统会选择库的最高版本。例如,如果 pom A 引用版本 1.1,pom B 引用版本 1.2,则 pom C(引用 A 和 B)将使用最高版本; 1.2.
此方法假设 1.2 与 1.1 100% 向后兼容,这是一个很好且必需的方法。然而,在图书馆生命周期的某些时候,清理商店是明智的。对我来说,API 中的任何重大更改都意味着增加主要版本,因此 2.0 不需要 100% 向后兼容最新的 1.x。美好的。
然而,Maven 并不真正关心,如果 pom B 从 1.2 升级到 2.0,Maven 将使用 2.0,但 pom A 无法使用该版本。
如何告诉 Maven 某个版本不再向后兼容?
我尝试指定排除范围,因此 A 指的是 [1.1,1.999),B 指的是 [2.0,2.999)。不过,Maven仍然解决了最大版本号(2.0)的问题。
Maven has a version management system that picks the highest version of a library if multiple versions are referenced. For example if a pom A refers to a version 1.1 and and pom B to 1.2, then a pom C (referring to both A and B) will use the highest version; 1.2.
This approach assumes that 1.2 is 100% backwards compatible with 1.1 and this is a good and required approach. However, at certain times in the lifecycle of libraries it is wise to clean up shop. For me any major changes in the API means increasing the major version, so a 2.0 does not need to be 100% backwards compatible to the latest 1.x. Fine.
Maven, however, does not really care and if pom B would be upgraded from 1.2 to 2.0, Maven would then use 2.0, but pom A cannot work with that version.
How to tell Maven that a version is no longer backwards compatible?
I've tried specifying excluding ranges, so A refers [1.1,1.999) and B refers [2.0,2.999). However, Maven still solves the maximum version number (2.0).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,使用 版本范围是一种不好的做法此外,在 Maven 构建中,您必须定义一个版本编号定义,其中 1.0 和 1.1 必须向后兼容,而 2.0 则不能,但这是您必须做出的定义。 Maven 并不知道这一点。我建议使用 Major.Minor.Increment-Qualifier 等在我看来,您应该修复您的版本,否则您将无法重现您的构建。
First it's a bad practice to use version ranges in Maven Builds furthermore you have to define a version numbering definition which says 1.0 and 1.1 must be backwards compatible whereas 2.0 is not but that's a definition you have to make. Maven does not know about that. I would recommend to use Major.Minor.Increment-Qualifier etc. In my opinion you should pin your versions fix otherwise you are not able to reproduce your builds.
我会更改工件 ID(可能通过添加主版本号)。这将使 1.x 和 2.x 版本与 Maven 不同。
I would change the artifact ID (probably by adding the major version number). This would make the 1.x and 2.x versions different beasts to Maven.
你研究过 Maven Enforcer 插件吗?它可能有类似的内容,或者您可以编写自定义规则。
Have you looked into the maven enforcer plugin? it may have something like this, or you may be able to write a custom rule.