Help:Using Composer/Add packages

From semantic-mediawiki.org

There are two possible methods on how to add packages using Composer. In both cases the execution of either composer update or composer require is required from the MediaWiki root directory.

composer.local.json[edit]

Extend your "composer.local.json" file and run composer update afterwards:

{
    "require": {
        "wikimedia/composer-merge-plugin": "~1.3",
        "mediawiki/semantic-media-wiki":"~2.5",
        "mediawiki/semantic-extra-special-properties": "~1.5",
        "mediawiki/semantic-breadcrumb-links": "~1.4"
    }
}
$ composer update
> ComposerHookHandler::onPreUpdate
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 20 installs, 0 updates, 0 removals
  - Installing symfony/css-selector (v3.3.9): Loading from cache
  - Installing onoi/shared-resources (0.4.3): Loading from cache
  - Installing wikimedia/textcat (1.2.0): Loading from cache
  - Installing onoi/tesa (0.1.0): Loading from cache
  - Installing onoi/callback-container (2.0.0): Loading from cache
  - Installing onoi/cache (1.2.0): Loading from cache
  - Installing onoi/http-request (1.3.1): Loading from cache
  - Installing onoi/blob-store (1.2.1): Loading from cache
  - Installing onoi/event-dispatcher (1.0.0): Loading from cache
  - Installing onoi/message-reporter (1.2.0): Loading from cache
  - Installing serialization/serialization (3.2.1): Loading from cache
  - Installing data-values/interfaces (0.2.5): Loading from cache
  - Installing data-values/data-values (1.1.0): Loading from cache
  - Installing data-values/validators (0.1.2): Loading from cache
  - Installing data-values/common (0.4.1): Loading from cache
  - Installing param-processor/param-processor (1.3.3): Loading from cache
  - Installing mediawiki/parser-hooks (1.5.0): Loading from cache
  - Installing mediawiki/semantic-media-wiki (2.5.4): Loading from cache
  - Installing mediawiki/semantic-extra-special-properties (1.5.0): Downloading (100%)
  - Installing mediawiki/semantic-breadcrumb-links (1.4.0): Loading from cache
mediawiki/semantic-media-wiki suggests installing mediawiki/semantic-result-formats (Additional result formats for SMW queries)
Writing lock file
Generating optimized autoload files

composer.json[edit]

Use composer require to invoke a change to the "composer.json" file.

$ composer require mediawiki/semantic-breadcrumb-links ~1.4
./composer.json has been updated
> ComposerHookHandler::onPreUpdate
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 1 update, 0 removals
  - Installing symfony/css-selector (v3.3.9): Loading from cache
  - Updating mediawiki/semantic-media-wiki (dev-master 0760344 => 2.5.4):  Checking out 9d8fac2960
  - Installing mediawiki/semantic-breadcrumb-links (1.4.0): Loading from cache
Writing lock file
Generating optimized autoload files

Difference between "composer.json" and "composer.local.json"[edit]

MediaWiki 1.25+ itself started to facilitate the use of "composer.json" for its own library dependency management therefore it has been suggested by MediaWiki core developers1 to use "composer.local.json" to add local packages to avoid merge conflicts with subsequent software updates. Since "composer.local.json" is a MediaWiki specific convention, composer require does not work on this file and instead has to be edited manually.

See also[edit]

References

  1. ^  Using composer-merge-plugin to "... allow local installs to use Composer to load optional libraries and/or manage extensions with Composer ... local deployment to add required extensions and libraries to a file composer.local.json inside the root MediaWiki directory"