简体   繁体   中英

Composer.json require my own private package

I'm trying to require my own package in another project, the original package is hosted in Bitbucket and has this 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/" }
    }
}

This package has branches master , develop and release/release-1.0.0 .

The project using this package has this 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"
}

When trying to require package "example/swagger-client" I get error:

[InvalidArgumentException]
Could not find package example/swaggerclient at any version for your minimum-
stability (stable). Check the package spelling or your minimum-stability

Also, this version of the command falis: php composer.phar require example/swaggerclient=dev

First, how can I know if the repository is not accessible or it is accessible but there is a problem with its version or its Composer file?

Second, how can I solve this problem?

I think there is too much in your repositories section.

This should be all you need:

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

Source: Composer Documentation - Using private repositories

(Posted on behalf of the OP) .

Apart from simplifying the packages section as @Peh sayed, I had to specify dev-develop version instead of * like this: "example/swagger-client": "dev-develop" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM