How to add dependencies for my plugin, so main app's composer will add it?

I’m making a plugin which needs the Cake notification plugin.

So in my plugin’s root there is a composer.json file. I’ve added the requirement for Cake Notification plugin there. Then in the main apps root, I’ve ran composer update. But checking vendors in the main app, I don’t see any changes. I check for vendors in the plugin root, and nothing there either.

Thanks in advance.

You will need to make a separate repository for the plugin and then add the repository to your composer file. This link has an example of how to do this. While in development, I would probably just install the dependency in the root cake composer file and then add it to the plugin when I was ready to ship it.

https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

No, I’m not modifying the plugin for use in my plugin. How do others do it? I add them in the main app composer and then running composer update installs the plugin and it’s dependencies (other plugins) into the main app vendor folder. The other dependencies are in their own folders as if they were added to the main app composer file.

Basically, I guess I’m looking for composer “chaining”?

Add the requirement to your plugin’s composer.json file, and make sure that you’ve pushed this and that it is appearing on packagist.

A composer update should work. If it doesn’t, try composer require --update-with-dependencies your/plugin

1 Like

Thanks Dakota.

I’m not familiar with packagist. If I do that, then my plugin becomes public? (It needs to be private…)

How are you installing the plugin? Is it via composer like explained here: https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

If it is not installed by composer, then composer won’t know about it’s dependencies. In that case you need to define the dependencies in your main applications composer.json file.

1 Like

Ok, I think that explains it. I did a manual install with my plugin in a generic host app. Then added it on the via the host app’s composer.json. Ran composer update. I guess that explains why nothing happened, the initial install needs to be done by composer, not manually.

Cheers, dakota!