Flutter 的 pubspec.yaml 中依赖版本号之前的插入符号 (^) 是什么? [英] What is the caret sign (^) before the dependency version number in Flutter's pubspec.yaml?

查看:39
本文介绍了Flutter 的 pubspec.yaml 中依赖版本号之前的插入符号 (^) 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Flutter 项目的 pubspec.yaml 文件中,在一些依赖项的版本号之前有一个脱字符 (^).

In the pubspec.yaml file of my Flutter project there is a caret (^) before the version number of some of the dependencies.

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  english_words: ^3.1.5

它的目的是什么?什么意思?

What is its purpose? What does it mean?

注意事项

  • I looked in the yaml documentation but I didn't see anything that made sense.
  • Related: what does Caret sign do in Dart (but it isn't an XOR operator here)
  • Related: In Flutter, Dependencies must specify version number? (an answer pointed me in the right direction but the question is asking something different)

推荐答案

插入符号 (^) 用于 pub 依赖项 在 Dart 中表示允许的版本号范围.具体来说,从指定版本到(但不包括)下一个非破坏版本的任何版本都可以.

The caret sign (^) is used for pub dependencies in Dart to indicate a range of version numbers are allowed. Specifically, any version from the specified version up to (but not including) the next non-breaking version is ok.

  • 所以 ^3.1.5'>=3.1.5 <4.0.0'
  • 是一样的
  • 并且 ^1.2.3 将与 '>=1.2.3 <2.0.0'
  • 相同
  • So ^3.1.5 is the same as '>=3.1.5 <4.0.0'
  • And ^1.2.3 would be the same as '>=1.2.3 <2.0.0'

这是较长形式的简写.

^ 是说,我想自动使用来自 Pub 的最新包,只要该更新不会破坏我的应用程序中的任何内容.

The ^ is saying, I want to automatically use the most up-to-date package from Pub as long as that update won't break anything in my app.

  • The concept of Semantic Versioning is important here. Read the article at the link if you are not familiar with it.
  • Version constraints documentation
  • Caret syntax documentation

原本以为

  • ^0.1.2'>=0.1.2 <1.0.0' (错误!) 相同强>

然而,这是对语义版本控制的错误理解.当主版本号为0(如0.1.20)时,表示API不稳定甚至次要版本号更改(如 0.1.21 中所示)可能表示发生了重大更改.

However, that is an incorrect understanding of Semantic Versioning. When the major version number is 0 (as in the 0 of 0.1.2), the meaning is that the API is unstable and even minor version number changes (as in the 1 of 0.1.2) can indicate a breaking change.

语义版本控制文章指出:

主要版本零 (0.y.z) 用于初始开发.任何事情都可能随时改变.公共 API 不应被视为稳定.

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

还有

在0.y.z初期开发中我应该如何处理修改阶段?

How should I deal with revisions in the 0.y.z initial development phase?

最简单的方法是开始您的初始开发版本0.1.0,然后为每个后续版本增加次要版本.

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

因此,以下是更正的形式:

Thus, the following is the corrected form:

  • ^0.1.2 等同于 '>=0.1.2 <0.2.0'

感谢 Günter Zöchbauer 指出我的错误.

Thank you to Günter Zöchbauer for pointing out my error.

这篇关于Flutter 的 pubspec.yaml 中依赖版本号之前的插入符号 (^) 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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