Configuring composer.json with private bitbucket mercurial repository

匿名 (未验证) 提交于 2019-12-03 07:36:14

问题:

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. And can't get it for the second day.

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"     } ] }

And running composer install I've got an error:

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

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

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

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"             }         }     } ]}

The same error occured:

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

I removed the part:

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

and got an error:

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

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"             }         }     } ]}

and an error:

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

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

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

}

Nothing helps. So I'm stuck and need help.

回答1:

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" },


回答2:

Just remove https://. Works for me :)

{ "require": {     "php": ">=5.4",     "myname/mylibname": "dev" },  "repositories":[     {         "type":"package",         "package":{             "name":"myname/mylibname",             "version": "dev",             "source":{                 "type":"hg",                 "url":"bitbucket.org/myname/mylibname",                 "reference":"dev"             }         }     } ]}


回答3:

That didn't quite work for me, but it got me pointed into the right direction. Make sure you get your SSH key installed to access it via git@.

{ "repositories": [ {   "type": "package",   "package": {     "name": "myname/mylibname",     "version": "master",     "source": {       "type": "git",       "url": "git@bitbucket.org:myname/mylibname.git",       "reference": "master"     }   } } ] }


回答4:

One comment on my end. I have tested above scenarios I encountered on composer suggestion that repository needs to have at least one stable version.

https://getcomposer.org/doc/04-schema.md#minimum-stability

Due to this, I used "dev" TAG along with SSH connection and it works.

{     "require": {         "php": ">=5.4",         "myname/mylibname": "dev"     },      "repositories":[     {         "type":"package",         "package":{             "name":"myname/mylibname",             "version": "dev",             "source":{                 "type":"git",                 "url":"git@bitbucket.org:myname/mylibname.git",                 "reference":"dev"             }         }     } ]}


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!