Skip to content

Install custom Drupal module from a git repository using composer

You have a git repository for a custom Drupal module you are developing, and you want to add the module to your Drupal project using composer.

You can do this by adding a composer repository of the type package for the module.

composer.json
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "package",
            "package": {
                "name": "custom/procoid",
                "version": "1.0",
                "type": "drupal-custom-module",
                "source": {
                    "type": "git",
                    "url": "git@gitlab.com:thomasdegraaff/sp-procoid.git",
                    "reference": "main"
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "custom/procapi",
                "version": "1.0",
                "type": "drupal-custom-module",
                "source": {
                    "type": "git",
                    "url": "git@gitlab.com:thomasdegraaff/sp-procapi.git",
                    "reference": "main"
                }
            }
        }
    ],

And then add the modules to your project.

composer require custom/procoid

Don't forget to read the composer package documentation.

Note: This repository type has a few limitations and should be avoided whenever possible:

Composer will not update the package unless you change the version field. Composer will not update the commit references, so if you use master as reference you will have to delete the package to force an update, and will have to deal with an unstable lock file.

But for my current purpose it is ok.

Back to top