Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Composer: How to override a requirement globally for composer.json?

TL;DR:

My Project requires library A, A requires B1. B1 is broken but there is a fork B2. I want to achieve that composer will install B2 instead of B1 even if A requires B1 and not B2.

How to do that?

More in detail:

In a symfony project we require the following library:

"require": {
   "emanueleminotto/twig-cache-bundle": "1.0.2",
}

This library requires itself another library that is currently broken:

"require": {
    "asm89/twig-cache-extension": "^1.3"
},

For the broken library exists already a pull request for over 4 month but the maintainer refuses to merge it.

My question is, if it would be possible to overwrite the dependencies also for sub-dependencies, that always the patched fork would be used instead of the original one?

For the asm89/twig-cache-extension exists the following fork with fixes: https://github.com/blackandred/twig-cache-extension

I tried to add this fork to my composer.json and registered the fork explicitly under "repositories":

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/blackandred/twig-cache-extension"
    }
],

and added the dependency also in my composer-json with a changed version to "dev-master":

"require": {
    "asm89/twig-cache-extension": "dev-master",
    "emanueleminotto/twig-cache-bundle": "1.0.2",
}

But since the emanueleminotto/twig-cache-bundle still requires the original library, composer ignores the fork and installs the original.

Anything i can do here?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I believe the docs have a good example for this scenario.

Basically you need to define an alias in your composer.json as following:

"require": {
    "asm89/twig-cache-extension": "dev-master  as 1.3",
    "emanueleminotto/twig-cache-bundle": "1.0.2",
}

Added by the questioner:

One step was still missing: "composer update asm89/twig-cache-extension"

about 4 years ago · Santiago Trujillo Report

0

Add the replace section into composer.json of your fork:

{
    "replace": { 
        "asm89/twig-cache-extension": "self.version" 
    } 
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!