问题
I need to install a single composer package into a project - maatwebsite/excel ~2.1.0
. Each time composer updates, it updates all packages in composer.json. How can I avoid updating packages aside from the excel library?
I have tried the following commands but they don't seem to be working:
composer require maatwebsite/excel ~2.1.0
composer require vendor/maatwebsite/excel ~2.1.0
composer update maatwebsite/excel ~2.1.0
composer update vendor/maatwebsite/excel ~2.1.0
I've also tried using the --lock attribute but that's also not working.
Can anybody tell me what I am doing wrong?
回答1:
To install a composer package with a specific version the docs suggest the use of a colon.
composer require maatwebsite/excel:~2.1.0 --no-update
Also, the composer cli tool composer help require
help reads:
Required package name optionally including a version constraint, e.g. foo/bar or foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"
So to use a space separated version number, you needed the quotation marks surrounding the package/version combination. That is:
composer require "maatwebsite/excel ~2.1.0" --no-update
should work for you too.
回答2:
To skip updates on any other package, simply add --no-update
to your call. This instructs Composer to only require that new package and not update anything else.
The resulting call could then look like the following:
composer require maatwebsite/excel ~2.1.0 --no-update
来源:https://stackoverflow.com/questions/41316792/installing-only-single-package-via-composer-without-updating-other-packages