Composer dependency from own forked repository

2020-04-18 06:34发布

问题:

I have gitlab repository https://gitlab.com/ajkosh/yii2-admin and below is my composer.json:

{
    "name": "haruatari/yii2-module-app",
    "description": "Empty module application on Yii2",
    "minimum-stability": "stable",
    "license": "MIT",
    "authors": [
        {
            "name": "Viktor Pikaev",
            "email": "haruatari@gmail.com",
            "homepage": "http://haru-atari.com/about"
        }
    ],
    "repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:ajkosh/yii2-admin.git"
        }

    ],
    "require": {
         "php": ">=5.4.0",
        "yiisoft/yii2": "2.0.15",
        "yiisoft/yii2-bootstrap": "~2.0.0",
        "yiisoft/yii2-swiftmailer": "~2.0.0",
        "paulzi/yii2-materialized-path": "^2.0",
        "kartik-v/yii2-widget-select2":"2.0.4",
        "ajkosh/yii2-admin": "dev"
    },
    "require-dev": {
      "codeception/codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },
    "config": {
    "fxp-asset": {
      "installer-paths": {
        "npm-asset-library": "vendor/npm",
        "bower-asset-library": "vendor/bower"
      }
    },
    "process-timeout": 1800},
    "scripts": {
        "post-create-project-cmd": [
            "yii\\composer\\Installer::postCreateProject"
        ]
    },
    "extra": {
        "yii\\composer\\Installer::postCreateProject": {
            "setPermission": [
                {
                    "runtime": "0777",
                    "web/assets": "0777",
                    "data": "0777",
                    "data/log": "0777",
                    "data/tmp": "0777",
                    "yii": "0755"
                }
            ],
            "generateCookieValidationKey": [
                "config/web.php"
            ]
        }
    }
}

I am trying to fetch yii2-admin from my own repository but I am getting below error when I am running composer update.

 Problem 1
    - The requested package ajkosh/yii2-admin could not be found in any version, there 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 minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - 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 common problems.

回答1:

You're using incorrect package name. On resolving dependencies package name in URL is irrelevant, the only name what matters is package name in composer.json. So Composer reads composer.json from your forked repository, and finds name mdmsoft/yii2-admin, because you don't changed it after forking. There is no ajkosh/yii2-admin at all. You should either update package name in composer.json in your fork:

{
    "name": "ajkosh/yii2-admin",
    "description": "RBAC Auth manager for Yii2 ",
    "keywords": ["yii", "admin", "auth", "rbac"],
    "type": "yii2-extension",
    ...

Or use source package name in your require section:

"require": {
    ...
    "mdmsoft/yii2-admin": "dev-master"
},