Andreas Gohr
Andreas Gohr

Reputation: 4945

composer: replace dependencies with local versions

I want to use a library that defines some extensive dependencies in its composer.json file, even though it only uses one or two small classes of those dependencies.

Is it possible to set up my require in a way that composer thinks I already have those dependencies and lets me use some self-defined minimal mock classes instead?

Example: I want package lib/a which in turn requires lib/b.

Normally I would have something like this in my composer.json:

"require": {
  "lib/a": "^2.2"
}

I thought that maybe 'provide' would fool composer:

"require": {
  "lib/a": "^2.2"
},
"provide": {
  "lib/b": "2.2.0"
}

But it seems to do nothing. Composer still downloads lib/b.

Is there any way to tell composer to ignore a certain dependency?

Upvotes: 3

Views: 2089

Answers (1)

Andreas Gohr
Andreas Gohr

Reputation: 4945

Turns out replace does what I want:

"require": {
  "lib/a": "^2.2"
},
"replace": {
  "lib/b": "*"
}

This tells composer that the package at hand replaces any version of lib/b

Upvotes: 2

Related Questions