This question already has an answer here:
I'm new to the composer
and I would like to know the difference between require
and require-dev
.
The composer website doesn't offer a good explanation the difference between these two.
The part that I don't get is Lists packages required for developing this package, or running tests, etc.
from Composer Official Docs.
The
require-dev
packages are packages that aren't necessary for your project to work and shouldn't be included in the production version of your project.Typically, these are packages such as
phpunit/phpunit
that you would only use during development.seems clear to me:
http://getcomposer.org/doc/04-schema.md
1. the packages used to develop a package
The key distinction is that Composer will only install
require-dev
dependencies for the "root package" – the directory where you runcomposer install
. The documentation describes this as:…and the
require-dev
documentation specifies that it is "root-only".In practice, this means that a package's
require-dev
dependencies aren't used if the package is being installed as a dependency for something else (ie it's installed to another project'svendor
folder).So if you have
phpunit
in therequire-dev
list for YourProject, and I clone down YourProject and runcomposer install
in theyourproject/
directory, Composer will installphpunit
toyourproject/vendor/
, because it's likely I'm doing some development on YourProject. As part of doing development I'll probably want to run YourProject's test suite, and to do that I'll needphpunit
.But, if I add YourProject as a dependency of MyProject, installing the
myproject
package will install theyourproject
package as well, but it will not installphpunit
.You can override this behaviour with the
--dev
and--no-dev
options, but the default behaviour is based on whether the package concerned is the root package.