【问题标题】:Composer.json require my own private packageComposer.json 需要我自己的私有包
【发布时间】:2017-03-10 05:07:34
【问题描述】:

我正在尝试在另一个项目中需要我自己的包,原始包托管在 Bitbucket 中,并且有这个composer.json

{
    "name": "example/swagger-client",
    "description": "",
    "keywords": [
        "swagger",
        "php",
        "sdk",
        "api"
    ],
    "homepage": "http://swagger.io",
    "license": "Apache v2",
    "authors": [
        {
            "name": "Swagger and contributors",
            "homepage": "https://github.com/swagger-api/swagger-codegen"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-mbstring": "*"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "satooshi/php-coveralls": "~0.6.1",
        "squizlabs/php_codesniffer": "~2.0"
    },
    "autoload": {
        "psr-4": { "Swagger\\Client\\" : "lib/" }
    }
}

这个包有分支masterdeveloprelease/release-1.0.0

使用这个包的项目有这个composer.json:

{
    "name": "example/example-api-client",
    "license": "proprietary",
    "type": "symfony-bundle",
    "description": "a description",
    "keywords": ["Symfony", "bundle", "jwt", "jws", "authentication", "api", "rest"],
    "repositories": [
                {
                    "type": "git",
                    "url": "https://bitbucket.org/example/swaggerclient-example.git"
                },
                {
                    "type":"package",
                    "package":{
                        "name":"example/swagger-client",
                        "version": "dev",
                        "source":{
                            "type":"git",
                            "url":"https://bitbucket.org/example/swaggerclient-example.git",
                            "reference":"*"
                        }
                    }
                }
    ],
    "require": {
        "php": ">=5.3.9",
        "symfony/http-kernel": "2.8.*",
        "symfony/security-bundle": "2.8.*",
        "eightpoints/guzzle-bundle": "^5.3",
        "example/swagger-client": "*"
    },
    "autoload": {
        "psr-4": {
            "ExampleOrg\\Bundle\\ExampleClientBundle\\": ""},
            "exclude-from-classmap": [
              "/Tests/"
            ]
    },
    "require-dev": {
        "symfony/framework-bundle": "2.8.*",
        "symfony/yaml": "2.8.*",
        "phpunit/phpunit": "^4.8",
        "symfony/phpunit-bridge": "~2.7",
        "symfony/browser-kit": "2.8.*"
    },
    "autoload-dev": {
      "psr-4": {
        "ExampleOrg\\Bundle\\ExampleClientBundle\\Tests\\": "tests"
      }
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "dev"
}

当尝试要求包 "example/swagger-client" 时出现错误:

[InvalidArgumentException]
在您的最低版本中找不到任何版本的包示例/swaggerclient-
稳定性(稳定)。检查包拼写或您的最低稳定性

另外,这个版本的命令falis:php composer.phar require example/swaggerclient=dev

首先,我如何知道存储库是不可访问还是可访问但其版本或 Composer 文件有问题?

其次,我该如何解决这个问题?

【问题讨论】:

  • 自动生成的 PHP 客户端应该附带一个 README 文件,其中包含有关如何包含发布到 git repo 的包的安装说明。这会有帮助吗?

标签: php composer-php


【解决方案1】:

我认为您的 repositories 部分内容过多。

这应该就是你所需要的:

{
    "require": {
        "vendor/my-private-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "git@bitbucket.org:vendor/my-private-repo.git"
        }
    ]
}

来源:Composer Documentation - Using private repositories

【讨论】:

  • 那不正确但没有引起问题,真正的问题是我必须在包的要求部分指定版本dev-develop
【解决方案2】:

(代表 OP 发布).

除了像@Peh 所说的那样简化包部分之外,我还必须指定dev-develop 版本而不是*,如下所示:"example/swagger-client": "dev-develop"

【讨论】:

    猜你喜欢
    • 2013-11-24
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    相关资源
    最近更新 更多