14

How can you write a require rule that excludes multiple specific versions of a library?

e.g. I have a require for any 1.7.* version of a library

"require": {
    "some/lib": "~1.7"
}

But then I find an issue with the library in version 1.7.3 and want to prevent that being installed, which can be done with:

"require": {
    "some/lib": ">=1.7, <1.7.3 | >1.7.3"
}

Which is already getting ugly. Then later on we find another issue with the library and want to exclude version 1.7.7. Trying to do the same syntax as above seems horrible, what is a better approach to excluding specific versions of a library?

TL:DR is there a syntax like this:

"require": {
    "some/lib": "~1.7, !1.7.3, !1.7.5"
}

that works?

2 Answers 2

29

Of course, found the answer 5 minutes after asking:

"require": {
    "some/lib": "~1.7, !=1.7.3, !=1.7.5"
}
1
  • 2
    I had to remove the , in order to make the exclude work.
    – scube
    Commented Mar 27, 2017 at 8:34
0

This also works for me on the command line.

composer require some/lib:!=1.7.3

Quotes may be needed for complex expressions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.