36

What is the difference in dependencies and dev_dependencies in a pubspec.yaml? It seems that when I run pub get the dev_dependencies aren't downloaded.

nbro
  • 15,395
  • 32
  • 113
  • 196
Austin Cummings
  • 770
  • 1
  • 8
  • 15

3 Answers3

20

dev_dependencies are dependencies that are not available for code in the resulting application, but only for tests, examples, tools, or to add executable tools like for code generation to your project.

dev_dependencies of any dependencies in your project (dependencies or dev_dependencies) are always ignored when you publish to pub.dev.

See also https://dart.dev/tools/pub/pubspec

Kab Agouda
  • 6,309
  • 38
  • 32
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 24
    IMHO, your explanation is not super clear. [Here](https://www.dartlang.org/tools/pub/dependencies#dev-dependencies)'s a good explanation. – nbro Sep 06 '18 at 23:40
16

There are two types of dependencies, one is regular and the other is dev.

dependencies:

Regular dependencies are listed under dependencies:—these are packages that anyone using your package will also need.

dev_dependencies:

Dependencies that are only needed in the development phase of the package itself are listed under dev_dependencies.


If your package (say A) depends on another package (say B) (which has dev-dependencies), then your package A ignores the dev-dependencies of package B.

However, your package A depends on the packages listed by Package B's dependencies.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
  • 1
    how I can decide which dependency will be placed under the ```dev-dependencies``` and which will be under ```dependency```. suppose I have to include dependency of ```image_picker```, now where should I place and why? – M.ArslanKhan Jan 11 '20 at 08:57
1

Pub supports two flavors of dependencies : dependencies and dev dependencies.

Dev dependencies differ from regular dependencies in that dev dependencies of packages you depend on are ignored. Here’s an example:

Say the transmogrify package uses the test package in its tests and only in its tests. If someone just wants to use transmogrify—import its libraries—it doesn’t actually need test. In this case, it specifies test as a dev dependency.
Its pubspec will have something like:

dev_dependencies:
  test: '>=0.5.0 <0.12.0'

Pub gets every package that your package depends on, and everything those packages depend on, transitively. It also gets your package’s dev dependencies, but it ignores the dev dependencies of any dependent packages. Pub only gets your package’s dev dependencies. So when your package depends on transmogrify it will get transmogrify but not test.

The rule for deciding between a regular or dev dependency is simple: If the dependency is imported from something in your lib or bin directories, it needs to be a regular dependency. If it’s only imported from test, example, etc. it can and should be a dev dependency.

Using dev dependencies makes dependency graphs smaller. That makes pub run faster, and makes it easier to find a set of package versions that satisfies all constraints.

Here, You can learn more about dependencies

Kab Agouda
  • 6,309
  • 38
  • 32