General developer forum

Plugin dependencies in composer?

 
Picture of Darko Miletić
Re: Plugin dependencies in composer?
Core developersParticularly helpful Moodlers

You need to ship the third-party libraries with plugin. That means following:

Create composer.json file in the root of your plugin dir.

Add whatever libraries you need like this:

{
    "require-dev": {
        "foo/fii-test": "1.6.1.*",
        "faa/feee":"3.0.0",
    }
}

Install composer binary on your system

Execute composer from within the root of your plugin this should download stuff into [yourplugindir]/vendor

That's it. You ship the json and vendor dir with your plugin.

Whenever you need to use some of the libraries just provide the include like this:

require_once($CFG->dirroot . '/path/to/module/vendor/autoload.php');
 
Average of ratings: -