1

I want to add https://github.com/googleads/googleads-php-lib library to my module Drupal 8 I try to add composer. json in the folder module but is not load when I installed module this is solution to upload this library without command "composer update "?

this is my composer.json

{
  "name": "drupal/googleads-php-lib",
  "description": "Integrates the googleads-php-lib library into Drupal",
  "type": "drupal-module",
  "require": {
    "googleads/googleads-php-lib": "25.0.0"
  }
}

1 Answer 1

3

composer.json has no bearing when you enable a module in the Drupal admin. Drupal only looks at the info.yml of a module to ensure any listed dependency (module only) exists and has been met. Using drush also won't work. You need Composer for this.

You would need to require your module via composer require drupal/mymodule - at which point any dependencies listed in require would also be pulled in. For that to work, your module would need to be posted on drupal.org, with the Drupal packages repository added to your root composer.json file.

You could also add a repository endpoint pointed at GitHub, Bitbucket or any other VCS service, add a baseline composer.json file to your project and require it that way, too.

You can also do composer require googleads/googleads-php-lib:25.0.0 from your Drupal root to pull in that package, but I would go the module route (so that package is always tied with the module).

5
  • Would it definitely need to be posted on Drupal.org? Is there a reason you couldn't point composer at a private repo to download a custom module? I guess there would be some effort involved to make it land in the right folder, but it kinda feels like composer would be able to handle that
    – Clive
    Commented Mar 31, 2017 at 19:23
  • 1
    You could also do that, sure. I guess the most generic approach would be a sandbox project on drupal.org, and you could offload it later to a private repo once you learn a bit more about Composer.
    – Kevin
    Commented Mar 31, 2017 at 19:25
  • Yeah good point
    – Clive
    Commented Mar 31, 2017 at 19:26
  • Updated my answer, I literally just did that moments ago with a private pattern lab repo.
    – Kevin
    Commented Mar 31, 2017 at 19:29
  • If it's a custom module for that site then adding the dependency to the main composer.json is fine. Or you can use the merge plugin like explained here: drupal.stackexchange.com/questions/217810/…. merge plugin supports wildcards, so you can include all custom composer.json files with web/modules/custom/*/composer.json. If it should be a reusable module then any private or public git repository (e.g. github) should work, you just need to add a composer repository.
    – Berdir
    Commented Apr 1, 2017 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.