Installing only single package via Composer without updating other packages

送分小仙女□ 提交于 2020-07-15 15:10:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!