Dependencies for development and production

92 views
Skip to first unread message

Thomas V. Worm

unread,
Nov 27, 2019, 9:48:53 AM11/27/19
to Flutter Development (flutter-dev)
I have an app, which uses a dependency, I develop myself.

So I have two versions of the same dependency:

one for production, fetched from the git repo and
one for development, fetched from a local path

When I add them to my pubspec-file

dependencies:
  my_lib:
    git:
      url: git@...mylib.git
      ref: master

dev_dependencies:
  my_lib:
    path: ../mylib

I get an error message from pub get:

"Because my_app depends on both my_lib from git and my_lib from path, version solving failed."

So how do I setup pubspec in correct way for development AND production, so that I do not need to change it all the time. I want to set it up once and check it into my git repo.

Thanks and regards
Thomas

Ralph Bergmann

unread,
Nov 27, 2019, 11:15:23 AM11/27/19
to Thomas V. Worm, Flutter Development (flutter-dev)
I guess you need something like this:

dependency_overrides:
json_serializable:
path: ../json_serializable

see https://github.com/dart-lang/json_serializable/blob/master/example/pubspec.yaml

Ralph

> "Thomas V. Worm" <t...@s4r.de> hat am 27. November 2019 um 15:48 geschrieben:
> --
> You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/c62ed3f9-7898-432b-a32e-6459f708de88%40googlegroups.com.

Thomas V. Worm

unread,
Nov 28, 2019, 11:09:57 AM11/28/19
to Flutter Development (flutter-dev)
Thanks.

But as far as I can see, dependency_overrides does something completely different: it overrides a dependency with another version. And it does this not only for the project itself but also for all dependencies (and dependencies of dependencies), which are used in the project.

That is absolutely not, what I wanna do.

I want to define different dependencies for production, development and test.

For example, the test suite is only needed, when running the tests. They are not needed, when running the app in development mode or in production.

Some helper dependencies giving me some information eg. about design issues when my app runs in development mode are not needed when the app is used in production.

Or like in my example: I want to load a dependency from a different location, when in development mode than when it is build for production use.

And I want to do this, without changing my pubspec file each time.

When using dependency_overrides, it works. But you have to take it out at a latter time. And as long as you do not want override dependencies in the dependency graph, it has no benefit over changing the dependency definition itself. It is practically the same.

Thomas
> To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages