If core devs are using a version of composer earlier than one that has getVersion() in it, they hit this error:

PHP Fatal error: Uncaught Error: Call to undefined method Composer\Composer::getVersion() in /Users/mike/Development/Drupal/core/lib/Drupal/Core/Composer/Composer.php:104

Looks like we can fall back on \Composer\Composer::VERSION;

https://github.com/composer/composer/commit/427116749558f99e4c04ffa3fe35...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mixologic created an issue. See original summary.

Mixologic’s picture

Heres a patch that goes back far enough to stop that issue.

Mixologic’s picture

greg.1.anderson’s picture

Future-proofing: since Composer::getVersion() has been added, it is possible that future versions of Composer may remove Composer::VERSION. This can't happen until at least 2.0, in theory, but still worth checking IMO, since we have nothing else constraining / checking our Composer version support.

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community

RTBC from me.

I rolled back to composer 1.6.5 and checked out drupal 8.7.x and did a composer install to reset everything.

I then checked out 8.8.x. Without the patch running composer install I get

PHP Fatal error:  Uncaught Error: Call to undefined method Composer\Composer::getVersion() in /Users/mike/Development/Drupal/core/lib/Drupal/Core/Composer/Composer.php:104
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(292): Drupal\Core\Composer\Composer::ensureComposerVersion(Object(Composer\Script\Event))
#1 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(215): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('Drupal\\Core\\Com...', 'ensureComposerV...', Object(Composer\Script\Event))
#2 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(96): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 phar:///usr/local/bin/composer/src/Composer/Installer.php(204): Composer\EventDispatcher\EventDispatcher->dispatchScript('pre-install-cmd', true)
#4 phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php(119): Composer\Installer->run()
#5 phar:///usr/local/bin/co in /Users/mike/Development/Drupal/core/lib/Drupal/Core/Composer/Composer.php on line 104
Fatal error: Uncaught Error: Call to undefined method Composer\Composer::getVersion() in /Users/mike/Development/Drupal/core/lib/Drupal/Core/Composer/Composer.php:104
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(292): Drupal\Core\Composer\Composer::ensureComposerVersion(Object(Composer\Script\Event))
#1 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(215): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('Drupal\\Core\\Com...', 'ensureComposerV...', Object(Composer\Script\Event))
#2 phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php(96): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 phar:///usr/local/bin/composer/src/Composer/Installer.php(204): Composer\EventDispatcher\EventDispatcher->dispatchScript('pre-install-cmd', true)
#4 phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php(119): Composer\Installer->run()
#5 phar:///usr/local/bin/co in /Users/mike/Development/Drupal/core/lib/Drupal/Core/Composer/Composer.php on line 104

I applied the patch and with composer install I get:

Script Drupal\Core\Composer\Composer::ensureComposerVersion handling the pre-install-cmd event terminated with an exception                                                                                                                        
  [RuntimeException]                                                                                                    
  Drupal core development requires Composer 1.9.0, but Composer 1.6.5 is installed. Please run 'composer self-update'.  
                                                                                                                        

I then manually grabbed composer 1.8.6 and composer installed with that and got:

Script Drupal\Core\Composer\Composer::ensureComposerVersion handling the pre-install-cmd event terminated with an exception
 [RuntimeException]                                                                                                    
  Drupal core development requires Composer 1.9.0, but Composer 1.8.6 is installed. Please run 'composer self-update'.  

I then ran composer self-update to get composer 1.9.0 and was able to successfully run composer install.

larowlan’s picture

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the quick turnaround

Committed 7db7b5a and pushed to 8.8.x. Thanks!

  • larowlan committed 7db7b5a on 8.8.x
    Issue #3073012 by Mixologic, greg.1.anderson, mikelutz: Detect Composer...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.