5

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": "git@bitbucket.org:username/custom-module.git",
          "reference": "master"
        }
      }
    }
],

The composer.json file from the custom module is the following.

{
    "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 this 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, there may be a typo in the package name.

Potential causes:

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

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

EDIT 1

I have added below to the composer.json file from the custom module but still same issue.

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

EDIT 2 : Seems recursive package download is not possible with composer. Refer Why can't Composer load repositories recursively? and Add support for installing libraries via asset-packagist

9
  • I don't see a composer.json file in that Drupal module (Rest UI). Are those still required?
    – Kevin
    Feb 8, 2019 at 15:21
  • I cant find that pacakge on packagist: packagist.org/search/?q=drupal%2Frestui Feb 8, 2019 at 15:38
  • 2
    They'd be on packages.drupal.org/8 that's why you have to declare it as a repo in your composer
    – Leigh
    Feb 8, 2019 at 16:12
  • I think you're right Kevin, something isn't setup right with restui. If you try doing "composer show drupal/restui" from the root of the site it cant be found so doesnt appear to exist
    – Leigh
    Feb 8, 2019 at 16:15
  • 1
    I asked because the Rest UI module requires at least Drupal 8.2.x.
    – apaderno
    Feb 11, 2019 at 7:58

2 Answers 2

3

Just for this question I created a dummy module at https://github.com/leymannx/custom_module which has a composer.json similar to yours with drupal/restui in the "require" section and "type": "drupal-custom-module".

And then in a D8 project's composer.json I adjusted the "repositories" section to look like this:

"repositories": [
    {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    },
    {
        "type": "github",
        "url":  "https://github.com/leymannx/custom_module"
    }
],

In the "installer-paths" section I added:

 "web/modules/custom/{$name}": ["type:drupal-custom-module"]

I then simply ran composer require leymannx/custom_module and it downloaded the module and drupal/restui both to the right places. Of course you now can ignore the custom module with your repo's .gitignore file.

I guess the trick was to have the "repositories" section adjusted like above. And I guess you also can use proper versioning for the custom module when you tagged some releases. Right now it just downloads dev-main.

7
  • Hi @leymannx, tried with this way still no success. For example we can consider brightcove module which has brightcove api dependency. drupal.org/docs/upgrading-drupal/… dependency is not being installed here. Mar 30, 2021 at 2:26
  • @miststudent2011 – Isn't this a different question then? See drupal.stackexchange.com/q/296802/15055.
    – leymannx
    Mar 30, 2021 at 6:03
  • @miststudent2011 – Have you also tried putting github above the composer repositories as suggested in the doc you linked? And you replaced github and the URL with what exactly when you tried it with brighcove?
    – leymannx
    Mar 30, 2021 at 6:04
  • Yes, done everything as suggested in guide and linked different question. Copy pasted everything from the guide and followed the guide exactly. Mar 30, 2021 at 7:25
  • > Isn't this a different question then? Yes, but linked here so that we can find a solution, which will be common for both . Commented there as well. Mar 30, 2021 at 7:26
3
+50

So after further looking into a way I was able to download required contributed modules while installing custom module. I am not sure if it is a correct way but it works to download dependencies.

By adding below snip to the root directory composer.json and executing

 composer require custom/custom_module

downloaded the required dependencies as well.

"extra": {
    "merge-plugin": {
        "include": [
            "core/composer.json",
            "modules/*/composer.json"
        ],
        "recurse": false,
        "replace": false,
        "merge-extra": false
    }
}

If anyone got better suggestions please suggest.

Note : The above method requires wikimedia/composer-merge-plugin which can be added by the below command.

composer require wikimedia/composer-merge-plugin
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.