1

Our project structure is look like below:

(b5df1cc)
common    -> package1 \
                       \
(56e0bc0)               \
common    -> package2 -----> myApp
                        /
(101aa16)              /
common    -> package3 /

myApp dependent on package1, pacakge2, package3, and package1, pacakge2, pacakge3 dependent on common package(git packages), but the common package(git packages) may have different commit hash. After run flutter packages get, it will show the error like:

Because every version of package1 from git depends on common from git {url: git@bitbucket.org:common.git, ref: b5df1cc, path: common} and every version of package2 from git depends on common from git {url: git@bitbucket.org:common.git, ref: 56e0bc0, path: common}, package1 from git is incompatible with package2 from git.
So, because myApp depends on both package2 from git and package1 from git, version solving failed.
Running "flutter pub get" in myApp...
pub get failed (1; So, because myApp depends on both package2 from git and package1 from git, version solving failed.)

Is it possible to set the version constraints or other way to ignore the "version solving failed" error for git packages? Because we can ensure that all the code from common package(git package) is compatible with pacakge1, package2, package3, if it can set the version constraints, like >=2.0.0 <3.0.0, we can let the version never reach 3.0.0, so myApp can compatible with package1, pacakge2, package3, etc.

Updated:

Use dependency_override can solve this problem, but the dependency_override need to be set in the myApp, when the common package is updated, we need to update the common package in myApp at the same time, say if I update the common package in package1, I need to update the common package in myApp too, which is not what I expected.

littlegnal
  • 425
  • 4
  • 14

1 Answers1

0

Possible workaround is using dependency_overrides

Note: it might break package1/2/3 as it forces to use them some version of common package, ignoring their constraints

Pavel
  • 5,374
  • 4
  • 30
  • 55
  • Yes, it is indeed possible to use `dependency_override`, but when the common package is updated, we need to update the common package in `myApp` at the same time, say if I update the common package in `package1`, I need to update the common package in `myApp` too. – littlegnal Aug 17 '20 at 11:15
  • Anyway your app uses only one single version of common package at the moment of time – Pavel Aug 17 '20 at 11:39
  • You should consider hosting a private pub.dev or using SaaS like cloudsmith.io – The Vinh Luong Sep 16 '20 at 02:55
  • @TheVinhLuong is there any guide about hosting a private pub.dev? – Pavel Sep 16 '20 at 12:47
  • 1
    @Pavel Yes, you can look into it here: https://github.com/dart-lang/pub-dev/blob/master/doc/development.md – The Vinh Luong Sep 16 '20 at 15:00