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

查看:925
本文介绍了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)

推荐答案

插入符号( ^ )用于发布依赖项表示允许使用一定范围的版本号。具体来说,从指定版本到(但不包括)下一个不间断版本的任何版本都是可以的。

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'

这是较长格式的缩写。

It's shorthand for the longer form.

^ 是说,我想自动使用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.1.2 is the same as '>=0.1.2 <1.0.0' (wrong!)

但是,这是对语义版本。当主版本号为 0 时(如 0.1.2的 0 ) code>),其含义是该API不稳定,甚至版本号也很小(如 0.1.2 <的 1 / code>)可以指示重大更改。

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.yz)用于初始开发。随时可能发生任何变化。不应认为公共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.yz初始开发
阶段我应该如何处理修订?

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'

  • ^0.1.2 is the same as '>=0.1.2 <0.2.0'

谢谢GünterZöchbauer指出了我的错误。

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

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

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