Get Composer to suggest dev packages to
Composer 2.4 added a feature that the
composer require command prompts to install the package with
--dev flag if the package being installed is meant to be used as a developer tool.
--dev flag is passed, the package is installed under
require-dev section in the
composer.json file, and other Composer commands (such as
dump-autoload, etc can optionally skip
Composer inspects the
keywords section of the
composer.json file being installed, and if it contains
static analysis as keywords, Composer prompts the user to install it with
--dev flag if it is not passed.
The prompt contains the reason why the package was determined to be a dev dependency:
The package you required is recommended to be placed in require-dev (because it is tagged as "testing") but you did not use --dev.
This feature is skipped if Composer is run in a non-interactive environment (such as CI builds or when
--no-interaction flag is passed).
If you publish a developer tool (such as testing tools, data fixture tools, debugging tools, etc.), you can make use of this feature so Composer interactively prompts the user to install them under
require-dev section in case the user forgets to use the
To do this, add one of the following keywords to the
keywords section of the package's
Keywords Composer uses to recommend a package as a dev dependency:
composer.json file, and add one of the keywords above to the
+ "keywords": ["dev"],
The keyword only needs to be present in the default branch, and not necessarily in all branches and tags.