使用私有Bitbucket Mercurial存储库配置composer.json [英] Configuring composer.json with private Bitbucket Mercurial repository

查看:165
本文介绍了使用私有Bitbucket Mercurial存储库配置composer.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用我自己的库,该库位于bitbucket.org上的私有Mercurial存储库中.该库未配置composer.json.

My project uses my own library which is in the private Mercurial repository placed on bitbucket.org. That library has no composer.json configured.

我试图使该库成为我项目的依赖项.

I try to make that library as a dependency to my project.

首先,我将以下字符串写入composer.json:

Firstly I wrote to composer.json the following strings:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[
    {
        "type": "hg",
        "url" : "https://bitbucket.org/myname/mylibname"
    }
]
}

运行composer install时出现错误:

[RuntimeException]
无法克隆 https://bitbucket.org/myname/mylibname ,无法从中读取软件包
中止:需要http授权

[RuntimeException]
Failed to clone https://bitbucket.org/myname/mylibname, could not read packages from it
abort: http authorization required

然后我将"type": "hg"更改为"type": "vcs"并收到另一个错误:

Than I changed "type": "hg" to "type": "vcs" and got another error:

[Composer \ Repository \ InvalidRepositoryException]
在https:/***/mylibname的任何分支或标记中均未找到有效的composer.json,因此无法从中加载软件包.

[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of https:/***/mylibname, could not load a package from it.

在进一步阅读文档之后,我在我的项目的composer.json中添加了对库的描述,并且看起来像这样:

After additional reading of documentation I added description of my library to the composer.json of my project, and it began to look so:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[

    {
        "type": "vcs",
        "url" : "https://bitbucket.org/myname/mylibname"
    },
    {
        "type":"package",
        "package":{
            "name":"myname/mylibname",
            "version": "dev",
            "source":{
                "type":"vcs",
                "url":"https://bitbucket.org/myname/mylibname",
                "reference":"dev"
            }
        }
    }
]}

发生相同的错误:

[Composer \ Repository \ InvalidRepositoryException]
在https:/***/mylibname的任何分支或标记中均未找到有效的composer.json,因此无法从中加载软件包.

[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of https:/***/mylibname, could not load a package from it.

我删除了该部分:

        {
        "type": "vcs",
        "url" : "https://bitbucket.org/myname/mylibname"
    },

出现错误:

[InvalidArgumentException]
未知的下载器类型:vcs.可用的类型:git,svn,hg,perforce,zip,rar,tar,gzip,phar,文件.

[InvalidArgumentException]
Unknown downloader type: vcs. Available types: git, svn, hg, perforce, zip, rar, tar, gzip, phar, file.

我将"type": "vcs"改回了"type": "hg",composer.json如下:

I changed "type": "vcs" back to "type": "hg", composer.json looks like:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[
    {
        "type":"package",
        "package":{
            "name":"myname/mylibname",
            "version": "dev",
            "source":{
                "type":"hg",
                "url":"https://bitbucket.org/myname/mylibname",
                "reference":"dev"
            }
        }
    }
]}

和一个错误:

[RuntimeException]
无法执行hg克隆'https:/***/mylibname''/path/to/myproject' 中止:需要http授权

[RuntimeException]
Failed to execute hg clone 'https:/***/mylibname' '/path/to/myproject' abort: http authorization required

除了composer.json之外,我的auth.json的结构是:

The structure of my auth.json, which lies besides of composer.json is:

{
"http-basic": {
    "bitbucket.org": {
        "username": "myusername",
        "password": "mypassword"
    }
}
}

推荐答案

在作曲者1.1之前的当前状态下,类似bitbucket-oauth方法的问题似乎是错误的.这意味着您必须在客户端上设置SSH密钥,或者如果您像我一样由于部署服务器而无法设置密钥,则必须使用基本身份验证.

Seems like bitbucket-oauth method is buggy in the current state as of 1.1 of composer. This means that either you must have setup the SSH key on the client or if you are like me and cant setup keys because of deployment server, you will have to use basic auth.

我完成这项工作的唯一方法是:

The only way I got this working was:

〜/.composer/auth.json

{
    "http-basic": {
        "bitbucket.org": {
            "username": "bitbucketUsername",
            "password": "PasswordToBitbucket"
        }
    }
}

composer.json

"repositories": [
        {
            "url": "https://username@bitbucket.org/username/my-package.git",
            "type": "git"
        }

],
"require": {
        "username/my-package": "dev-master"
},

这篇关于使用私有Bitbucket Mercurial存储库配置composer.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆