What's the difference between pub dependencies and dev_dependencies? What's the difference between pub dependencies and dev_dependencies? dart dart

What's the difference between pub dependencies and dev_dependencies?


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


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.


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 everythingthose packages depend on, transitively. It also gets your package’sdev dependencies, but it ignores the dev dependencies of any dependentpackages. Pub only gets your package’s dev dependencies. So when yourpackage 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