Merge pull request #12204 from nextcloud/backport/12201/stable30

[stable30] fix: Dependency hell documentation
This commit is contained in:
Louis
2024-09-15 10:59:19 +02:00
committed by GitHub

View File

@@ -4,7 +4,7 @@
Dependency management
=====================
It's possible to build a Nextcloud app with existing software packages.
You can leverage existing software packages to build a Nextcloud app.
.. _app-composer:
@@ -34,6 +34,84 @@ Dependency hell
Be careful with which packages you add to an app. PHP can not load two version of the same class twice, hence there can be conflicts between Nextcloud Server and an app or between two or more apps if they require the same package. So try to keep the number of production dependencies to a minimum and see :ref:`app-composer-bin-tools`.
Alternatively you can use [composer-bin-plugin](https://github.com/bamarni/composer-bin-plugin) to avoid dependency conflicts between apps.
1. Install composer-bin-plugin according to their docs.
.. code-block:: shell
composer require --dev bamarni/composer-bin-plugin
2. Install the tools you need in the vendor-bin directory.
.. code-block:: shell
composer bin psalm require --dev psalm/phar
composer bin psalm require --dev nextcloud/ocp:dev-master
3. Adjust some config (see below)
- Add in `composer.json`:
.. code-block:: json
:caption: composer.json
{
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
}
}
- Add in `composer.json`:
.. code-block:: json
:caption: composer.json
{
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi"
]
}
}
- Adjust `psalm.xml`:
- Ensure the schemaLocation is correct:
.. code-block:: xml
:caption: psalm.xml
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/psalm/vendor/vimeo/psalm/config.xsd"
- Ensure it has something like this:
.. code-block:: xml
:caption: psalm.xml
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor-bin" />
</ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor" />
<directory name="vendor-bin/psalm/vendor" />
</extraFiles>
- Adjust `.php-cs-fixer.dist.php`
.. code-block:: PHP
:caption: .php-cs-fixer.dist.php
require_once __DIR__ . '/vendor-bin/cs-fixer/vendor/autoload.php';
Conflict example
****************