2

For example I have two modules, Demo and Base. I want that when Module Demo gets installed, module Base is automatically fetched from Github and installed.

I think it is related to composer.

Edited i trying to put code file composer.json of module A

{
    "name": "namespace/modulea",
    "description": "N/a",
    "require": {
        "php": "~5.6.0|7.0.2|~7.0.6",
        "magento/module-store": "100.1.*",
        "magento/module-backend": "100.1.*",
        "magento/framework": "100.1.*",
        "namespace/moduleb": "101.0.1"
    },
    "type": "magento2-module",
    "version": "101.1.3",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Namspace\\ModuleA\\": ""
        }
    },
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/xxx/moduleb.git"
        }
    ]
}

it true?

4

The composer.json of module B should contain:

"require": {
    "module/a": "*"
}

Where module/a is the name as defined in the composer.json of module A.

* means "any version", but you should replace that with a version dependency, like 1.0.0 for exactly 1.0.0 or ~1.2.3 for anything from 1.2.3 but below 1.3.0

Versions should be Git tags.

Read more: https://getcomposer.org/doc/


One more thing to consider: if module A is not on the Magento marketplace, but only on Github, the project where module B is installed needs to define the repository in its composer.json:

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/module/a.git"
    }
]

But you can publish module A to packagist, the default composer package repository to avoid that step.

  • Thanks @fabianschmengler I edited my question. How to when i run cli: php bin/magento setup:upgrade it auto get ModuleB in github and install this. – xanka Jan 5 '17 at 9:47
  • Not possible with bin/magento, you need to run composer install first. And it only works if you install the first module with composer as well – Fabian Schmengler Jan 5 '17 at 12:54
  • Note that the marketplace installer uses composer internally, so if module B is installed from marketplace, module a will be installed from github as well – Fabian Schmengler Jan 5 '17 at 12:55
  • "thanks" @fabianschmengler.I had build a module Base it's module parent for some my module future and i want when user installing module child then auto get module Base. Any suggestion? – xanka Jan 5 '17 at 13:05
  • I already answered it. If this is not working for you, you should update your question with details about how users install your module or why a composer based solution is not working for you (or what you do not understand about it) – Fabian Schmengler Jan 5 '17 at 13:24

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.