Upgrading to Drupal 9 and Composer 2

This article will explain how to deal with some specific and concrete issues you might encounter during the upgrade to Drupal 9 and Composer 2.

I've written a detailed article on how to upgrade Drupal 8 to 9, so you can check that if you want to get a general overview of the upgrade process. I didn't want to update that article with these specific issues as it is already quite long.

Issue #1 - cweagans/composer-patches

The "cweagans/composer-patches" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.1.0"). You may need to run composer update with the "--no-plugins" option.

If you upgrade Composer from version 1 to version 2 and you get this error message while running composer update or composer require commands, that means that you have an old version of cweagans/composer-patches package.

Versions 1.6.7 and older support only Composer 1, so before you upgrade Composer to version 2, you have to upgrade cweagans/composer-patches package to version 1.7.0 or newer.

Issue #2 - zaporylie/composer-drupal-optimizations

The "zaporylie/composer-drupal-optimizations" plugin was skipped because it requires a Plugin API version ("^1.1") that does not match your Composer installation ("2.1.0"). You may need to run composer update with the "--no-plugins" option.

Composer 1 is slow when used in big projects with a lot of dependencies. Very slow. And this composer plugin speeds things up at least a bit. Composer's speed is no longer an issue in version 2, so using this plugin is not needed.

To fix the issue update the plugin to version 1.2.0 which supports Composer 2, or even better since it actually doesn't do anything just remove it from your project by running:

composer remove zaporylie/composer-drupal-optimizations

Issue #3 - drupal/core-composer-scaffold

The "drupal/core-composer-scaffold" plugin was skipped because it requires a Plugin API version ("^1.0.0") that does not match your Composer installation ("2.1.0"). You may need to run composer update with the "--no-plugins" option.

Versions 8.8.x and older of this plugin support only Composer 1. To get Composer 2 support, you have to update the plugin to at least version 8.9.x.

Issue #4 - doctrine/reflection

Package "doctrine/reflection" is abandoned, you should avoid using it. Use "roave/better-reflection" instead.

The doctrine/reflection package is abandoned and is no longer maintained, and that's why Drupal core is no longer using it. The package will stay in Drupal 9 and will be removed before Drupal 10 is released. The code from the package has been copied to Drupal core per this change record.

Just ignore this message. There's nothing you can do here.

Issue #5 - webmozart/path-util

Package "webmozart/path-util" is abandoned, you should avoid using it. Use "symfony/filesystem" instead.

The package is abandoned because it's been merged into the Symfony Filesystem package, so it's not maintained anymore.

Drush requires it, so there's nothing you can do to fix this warning. Just ignore it, and wait for Drush maintainers to fix it.

Composer 2 backward compatibility

Composer 2 is backward compatible with Composer 1, so in theory, you can use Composer 2 on your machine while your teammates and/or CI/CD tools still use version 1. But that's probably not such a good idea.

Drupal's Lenient Composer endpoint

If you want to install modules that are not yet compatible with Drupal 9 but there are patches available to make them compatible, then you can use Drupal's Lenient Composer endpoint.

This works only if you are using Composer 2! 

Add the Lenient endpoint before the standard endpoint like this:

"repositories": {
    "lenient": {
        "type": "composer",
        "url": "https://packages.drupal.org/lenient"
    },
    "0": {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    }
},

This will enable Composer to download modules that are not compatible, but please remember that you still have to add patches to your composer.json file to make them compatible with Drupal 9. Composer will not do this for you automatically!

About the Author

Goran Nikolovski is a creator, speaker, open-source contributor, web developer specialized in Drupal and DevOps enthusiast. He is the founder of this website and he enjoys sharing his knowledge and experiences.