应用程序与软件包之间的软件包依赖

huangapple go评论123阅读模式
英文:

Package dependency between application and package

问题

这只是用来模拟使用包的情况。假设这个包可以是我没有开发的开发者包。

我们还假设我有一个简单的应用程序,具有以下pubspec.yaml依赖项:

dependencies:
  flutter:
    sdk: flutter
  webview_flutter: x2.y2.z2
  package_name:
    path: PATH_TO_LOCAL_PACKAGE

我正在尝试解决以下问题:

  1. 如果包的webview_flutter版本高于应用程序的版本
  2. 如果包的webview_flutter版本低于应用程序的版本

我收到的错误是:

因为路径上的package_name的每个版本都依赖于webview_flutter 2.4.0,而解析依赖关系依赖于webview_flutter 2.3.0,因此禁止使用路径上的package_name。
因此,因为解析依赖关系依赖于路径上的package_name,版本解决失败。
pub get 失败

在这两种情况下,如果x1和x2相等(意味着相同的主版本号),可以使用**插入符号(^)**语法轻松解决(来源于这里)。

我的问题是当主版本号(x1,x2)不同的时候。

例如,

x1.y1.z1 = 3.0.0
x2.y2.z2 = 2.3.0

我知道依赖重写选项,但这不是我想要做的事情。

显然,在包的版本高于应用程序的情况下,我可以更新应用程序,但在包的版本高于应用程序的情况下,我将无法这样做。

是否有没有使用依赖重写的方法来解决这种情况?

英文:

Let's say that I created a local package that has this pubspec.yaml dependencies:

dependencies:
  flutter:
    sdk: flutter
  webview_flutter: x1.y1.z1. /// Just an example of a package

This is just to simulate working with a package. Imagine that this package can be a developer package that I did not develop.

Let's also assume that I have a simple application with the following pubspec.yaml dependencies:

dependencies:
  flutter:
    sdk: flutter
  webview_flutter: x2.y2.z2
  package_name:
    path: PATH_TO_LOCAL_PACKAGE

I am trying to resolve the following issues:

  1. If the package has a version of webview_flutter that is higher than that of the application
  2. If the package has a version of webview_flutter that is lower than that of the application

The error I get is:

> Because every version of package_name from path depends on webview_flutter 2.4.0 and resolving_depedencies depends on webview_flutter 2.3.0, package_name from path is forbidden.
> So, because resolving_depedencies depends on package_name from path, version solving failed.
> pub get failed

In both of these scenarios, if x1 and x2 are equal (meaning the same major version), this can be solved easily with the caret (^) syntax (taken from here).

My problem is when the major versions (x1, x2) are different.

For example,

x1.y1.z1 = 3.0.0
x2.y2.z2 = 2.3.0

I am aware of the dependency overrides option, but it is not something I want to do.

Obviously, in the scenario where the package has a higher version than the application, I can update the application, but in the scenario where the package has a higher version, I won't be able to do that.

Is there any way to solve this scenario without dependency overrides?

答案1

得分: 1

首先,我建议你阅读这个文档,它非常棒,可以帮助你理解pub如何解决你的依赖关系。

从文档中,我们了解到:

  • pub将每个依赖项解析为一个唯一版本
  • 正如这里所述,你可以拥有不相交的约束条件,这会使解析变得不可能。

在你的情况下,如果包的webview_flutter版本低于你的版本,那么你只能使用它的版本,或者使用dependency_overrides(这是非常危险的,因为它可能会破坏依赖于较低版本的包)。

你的下一步应该是要求包的维护者更新其依赖项,同时降级你的依赖版本。

英文:

First, I advise you to read this documentation which is awesome to understand how pub resolves your dependencies.

From that documentation, we learn that:

  • pub resolves each dependency to a unique version.
  • As stated here, you can have disjoint constraints which makes the resolving impossible.

In your case, if the package has a lower version of webview_flutter than you, then you are bound to use its version at most, or to use dependency_overrides (which is highly dangerous because then it might break the package which depends on a lower version).

Your next step should be to ask the package maintainer to update its dependency, and to downgrade your version of the dependency in the meantime.

huangapple
  • 本文由 发表于 2023年3月9日 15:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75681673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定