0

I have project A, which requires package B. Package B does not contain the composer.json file directly, but has this file named differently (it contains more than one). In the composer.json file in project A, I have added package B to the repositories section (VCS type). In the require section, I have written the specific branch I want to install (also with the dev- prefix). When I run composer update, composer throws me the error

Root composer.json requires ...... but these do not match your constraint and are therefore not installable. Make sure you either fix the constraint or avoid updating this package to keep the one present in the lock file.

Also the composer show command does not show me that branch. Is the problem that package B does not contain composer.json directly? Is there any way to tell composer which composer file to use from package B?

Package B has 3 composer.json files because it has a dependency on package C, which has 3 branches, production, staging and development, where development is the internal development/testing environment, staging is the testing environment for our clients and production is the production environment. And likewise, package B has these three branches and therefore has 3 composer.json files to use the correct version/branch from package C (which has only 1 composer.json file, because it doesn't have that other dependency) for each environment. And likewise, application A has this and I need to be able to install package B in the appropriate version/branch.

  • 2
    Why does your package contain a `composer.json` with a different name? Why not use the file name that works, which is `composer.json`? – Nico Haase Nov 22 '22 at 10:44
  • 2
    "Package B has different versions" - why not use seperate branches for this? – Nico Haase Nov 22 '22 at 10:45
  • "_but has this file named differently (it contains more than one)_" Your package has more than one composer.json? Why? – brombeer Nov 22 '22 at 10:58
  • Because **Package B** is using [gitworkflow](https://stackoverflow.com/a/51917133/2754392), those different `composer.json` files are for different environments. And it would be a pain to have one file and always merge it between branches. – František Šitner Nov 22 '22 at 11:02
  • I have no clue what "gitworkflow" means in this context, but I doubt that Composer knows anything about this. It searches for `composer.json`. But I would assume that the error message you've shown might mean something else - `requires ...... ` what is hidden behind the dots? – Nico Haase Nov 22 '22 at 12:57
  • I know that composer knows nothing about "gitworkflow", I'm just explaining the reason why **package B** has multiple `composer.json` files. Behind the dots is just list of found names of the other branches. I tried it again because in the meantime I tried to change one file to `composer.json`, which successfully installed and wrote the lock file and now I changed it back to a different name and it returned `Root composer. json requires package-name branch-name@dev, found package-name[branches......] but it does not match the constraint.` – František Šitner Nov 22 '22 at 14:04
  • It is not clear from your question to me what you ask about here. Earlier comments are correct in regard of the *default* basename of the composer project configuration file which is controlled by the environment parameter named `COMPOSER`. If unset or empty, the parameters default value is said `composer.json`. Unless you keep the default parameter value composer will always look for `composer.json`. Configure the invocation accordingly if you want to load a configuration from a file under a different name. Compare _environment_ in the Composer documentation. – hakre Nov 22 '22 at 16:36
  • 1
    And _gitworkflow_ (using git for configuration management with different branches) gives no inherent requirement that would explain why there are different composer project configuration files. Double check with the maintainer of the setup you understand it correctly, not that these are files in a database, e.g. to keep configurations for different versions and not to be used for composer invocations resolving project dependencies for the in-tree build. – hakre Nov 22 '22 at 16:40
  • Let me try to explain it better. **Package B** has 3 `composer.json` files because it has a dependency on **package C**, which has 3 branches, `production`, `staging` and `development`, where `development` is the internal development/testing environment, `staging` is the testing environment for our clients and `production` is the production environment. – František Šitner Nov 23 '22 at 07:07
  • And likewise, **package B** has these three branches and therefore has 3 `composer.json` files to use the correct version/branch from **package C** (which has only 1 `composer.json` file, because it doesn't have that other dependency) for each environment. And likewise, **application A** has this and I need to be able to install **package B** in the appropriate version/branch. – František Šitner Nov 23 '22 at 07:07
  • 1
    Please keep in mind to add **all** clarification to your question by editing it. Don't use the comment section for important details – Nico Haase Nov 23 '22 at 07:11
  • I'm sorry, my mistake. I tried to update the original question. – František Šitner Nov 23 '22 at 09:27
  • 1
    If you keep different configurations per tree/package to prevent merge conflicts between branches, you have to build each tree first and create the composer.json file there (which looks to me like a file-copy operation from ${branch}.json to composer.json). Given correct composer repository configuration in the root package, composer should be able to find those. However this contradicts the normal git/composer workflow as you have to build the packages first. Perhaps better is to have release branches in `B`,`C` that are just commits with that copy operation. Then require from those branches. – hakre Nov 24 '22 at 09:48
  • Okay, so if I understand correctly, that means there is no way to tell composer which `composer.json` file to look at when installing, but there always has to be a `composer.json` file directly? – František Šitner Nov 25 '22 at 07:38

0 Answers0