miststudent2011
miststudent2011

Reputation: 299

How to install custom module and its dependencies with composer in Drupal 8

Hi I am trying to setup my new Drupal 8 site with composer, but I got few issues.

I tried to setup the site site by following the Guide from here and was able to setup the site successfully.

After that I tried to install a custom module which is hosted on Bitbucket and I am able to download the package using composer, but the problem is the module has some other contributed module dependency but the dependency module is not downloaded along with the custom module.

I followed the guide from here and added composer.json file to my custom module along with the dependency but after running composer require custom/custom_module only the custom module is installed but not the dependency.

My root directory composer.json file repositories section looks like this :

"repositories": [
    {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    },
    {
      "type": "package",
      "package": {
        "name": "custom/custom_module",
        "version": "master",
        "type": "drupal-custom-module",
        "source": {
          "type": "git",
          "url": "[email protected]:username/custom-module.git",
          "reference": "master"
        }
      }
    }
],

and the composer.json file from the custom module looks as below :

{
    "name": "custom/custom_module",
    "description": "This is a Custom Module with Different functionalities.",
    "type": "drupal-custom-module",
    "minimum-stability": "dev",
    "require": {
        "drupal/restui": "~1.16"
    }
}

I also chaged the line "drupal/restui": "~1.16" as "drupal/restui": "^1.16" but with no success.

I even tried running composer update in the custom module directory as I was not sure whether dependencies will be installed along with custom module.

After running composer update in the custom module directory I got the following error:

Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package drupal/restui could not be found in any version, the re may be a typo in the package name.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your min imum-stability setting see https://getcomposer.org/doc/04-schema.md#minimum-stability for more det ails. - It's a private package and you forgot to add a custom repository to find it

Read https://getcomposer.org/doc/articles/troubleshooting.md for further commo n problems.

But on Drupal.org I can find the module with that version here

Please help me to solve the issue.

Upvotes: 1

Views: 2806

Answers (1)

zanvidmar
zanvidmar

Reputation: 421

Try this:

Root composer.json section

 "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    },
    {
      "type": "vcs",
      "url": "[email protected]:username/custom-module"
    }
  ],

Module composer.json example that has two modules as dependency

{
  "name": "username/custom-module",
  "version": "1.2.3",
  "type": "drupal-custom-module",
  "description": "Custom module",
  "keywords": ["Drupal"],
  "license": "GPL-2.0+",
  "minimum-stability": "dev",
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  ],
  "require": {
    "drupal/admin_toolbar": ">=1.2",
    "drupal/chosen": ">=2.6"
  }
}

Upvotes: 0

Related Questions