行家;如何打破向后兼容性?

发布于 2024-10-29 20:15:43 字数 457 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦过后 2024-11-05 20:15:43

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.

旧梦荧光笔 2024-11-05 20:15:43

我会更改工件 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.

笑咖 2024-11-05 20:15:43

你研究过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文