Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 508
Andreas Gohr Avatar asked Jan 30 '26 14:01

Andreas Gohr


1 Answers

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

like image 97
Andreas Gohr Avatar answered Feb 02 '26 06:02

Andreas Gohr