How are Local Shopware Plugin composer.json Dependencies Managed?
Asked Answered
P

1

6

In a Shopware system, there's a main composer.json file. This manages the main project dependencies. In addition to this, Shopware plugins require you to add a composer.json file. If these plugins are added to the system via the main composer.json file, then the dependencies in a plugin's composer.json file will end up in the root level vendor/ folder. This I understand.

However, it appears that plugins can also be installed locally outside of the vendor folder, in either

  • ./custom/plugins or
  • ./custom/static-plugins

When a plugin is installed locally, how should its dependencies be managed?

Is the intent that, when installing a plugin locally you'll also add its dependencies to the main composer.json file? Or is there a way to tell shopware

Hey, install this plugin's dependencies

Also -- how do the ./custom/plugins/*/packages folders enter into this? It's my vague understanding that these are for private plugin dependencies, but I'm not sure what that means or how that code should be managed

Or am I misunderstanding the intent behind these local folders, and the expectation in Shopware 6 is that all plugins should be installed via your main composer.json file and the custom/ folders are just legacy?

Or some other thing?

Pardoes answered 18/5, 2021 at 18:19 Comment(0)
W
7

If your plugin lives within the custom/static-plugins folder, you can just composer require my/plugin from the root. So that's the way to use composer plugins within your project. Shopware is then searching for the composer plugin within the custom/static-plugins/* repository.

Take a look at the Require project plugins section within the Docs on how to deal with requiring composer plugins.

Within the custom/plugins folder you have all your store plugins. That's also the reason why the content of the custom/plugins folder is not committed to your git repo. Because plugins within custom/plugins are coming from the Shopware store. However: You can still also just place your plugins within the custom/plugins folder if you want to.

Regarding custom/plugins/*/packages: You're right. Take a look at the adding private composer dependencies section within the docs.

Wabash answered 19/5, 2021 at 5:5 Comment(5)
Are the "private dependencies" real private to a plugin or would they conflict with each other, if two plugins ship conflicting versions of such dependencies?Garlan
if you install those two plugins with composer require in your root composer.json. there would be a conflict. or they would both use the version of one plugin. depending on how the requirements are definedPaolapaolina
That makes sense and is useful Christopher. I still have one big unanswered question. If I have something like custom/plugins/SomePlugin/composer.json, is shopware doing anything to install the dependencies listed in custom/plugins/SomePlugin/composer.json?Pardoes
No - You would need to ship the plugin with the whole vendor folder then, install the dependencies within your CI or just make a composer install within your plugin on the server manually.Wabash
"no" is not totally right here :-) you can also require your plugin in your Shopware composer. then the dependencies of your plugin will be resolved in the Shopware vendor directory and you do not need to ship them. but this is only practical if it is local plugin for your project. or it is public available on packagist or GitHub or so. if you want to publish the plugin in the store, you still need to ship the dependencies. but this will also change in a future major version. hopefully 6.5.0.0Paolapaolina

© 2022 - 2024 — McMap. All rights reserved.