Composer and Drupal: striking the right notes in dependency management

May 29, 2017
Composer and Drupal: striking the right notes in dependency management

It’s often called one of the greatest tools ever in the PHP world. It’s called Composer, and it’s the real master of dependencies. The benefits of using it with Drupal are unquestionable. Moreover, beginning with Drupal 8, you can hardly do without Composer. Using it means adhering to the best practices. The great opportunities for using Composer are among Drupal 8’s best developments alongside mobile improvements, better accessibility, handier configuration management and all the other things we love so much. More details are coming right now.

Though there is no strict requirement in Drupal 8 to use Composer, you can quickly “run into walls” when building a typical Drupal 8 site without the help of Composer, says Jeff Geerling, Acquia’s Senior Technical Architect and the creator of over 150 modules. Despite being used for a couple of years already, Composer has only reached stable status recently. Drupal 8 is the first major version of Drupal where people are using it to manage dependencies. Jeff shares these ideas in his article about the current issues in managing Drupal websites with the help of Composer.

Composer and what it does for Drupal

As a dependency manager for PHP, Composer will free you from any fuss in locating, installing, updating, and validating your project’s dependencies. Just tell Composer which dependent libraries or packages you need, and it will consistently do the job for you. All the dependencies, together with related metadata, are described in the composer.json file and stored in repositories, with the main one being Packagist.

The Drupal core itself relies on Composer for managing the external libraries it depends on. It includes a composer.json file with all of them listed. Contributed modules can choose to have it as well.

So Composer can be very helpful to you in managing both the core and modules of your existing website, as well as setting up a new website. It can be used for installing and updating the Drupal core, modules and themes with all the dependencies, adding third-party libraries to modules, patching modules and the core, and much more.

Contributed module maintainers can add dependencies to their modules by adding a composer.json file to their projects. Custom project developers are also welcome to manage dependencies via Composer. The tool is great for everyone!

Working with Composer

You can download Composer here. The special Drupal Composer Template can give you a kickstart in managing your dependencies with Composer.

Of course, the Drupal community always comes up with great modules for everything. If you are using Drupal 8, but not yet Drupal 8.1 or higher, you can use a great assistant called the Composer Manager module that will help you manage Composer files. Beginning with Drupal 8.1, the core uses Composer directly for dependency management.

Composer is in some ways a replacement for Drush Make, so it is useful to see the differences in how both of them work.

We hope you have the best experiences using Composer with Drupal. Let your project always be in perfect harmony, like a well-composed song! And remember: you can safely rely on Drudesk support guys for this task. Composer can perfectly manage dependencies, and we can perfectly manage great tools such as Composer.

 Get new blog posts by email