8

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?

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
Laki98
  • 81
  • 1
  • 2
  • 4
  • Should be able to edit composer.json to set the package version you want (~2.1.0), and then just `composer update maatwebsite/excel` – drew010 Dec 24 '16 at 21:03
  • @Laki98 I am sure the composer might be updating only the dependencies of the `maatwebsite/excel` package and not everything in your vendor folder. Can you paste the output? – prateekkathal Dec 24 '16 at 21:36
  • @prateekkathal it has downloaded and updated all dependencies again, just like did before. I'll copy the output right down in the answer. – Laki98 Dec 24 '16 at 23:00
  • @Laki98 You can take a sreenshot and give me that link also... – prateekkathal Dec 24 '16 at 23:03
  • It's updating the dependencies required by the package you're updating. Nothing wrong here. You can exclude the dev dependencies by doing `composer update --no-dev maatwebsite/excel`. – drew010 Dec 24 '16 at 23:20
  • @drew010 i ran "composer update --no-dev maatwebsite/excel" and it actually downloaded most of the packages (not only excel's one), but seemed to work after that. Thank you so much! – Laki98 Dec 25 '16 at 10:17

2 Answers2

4

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.

Ross
  • 3,022
  • 1
  • 17
  • 13
  • 2
    Thanks for quick answer but again, in both ways ALL dependencies from composer.json are being updated. – Laki98 Dec 24 '16 at 22:36
1

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
Nico Haase
  • 11,420
  • 35
  • 43
  • 69