How do i use Composer to install a package without a version (only master)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 07:24:10

问题


I am new to composer and i am trying to install this following lib via the composer update

https://github.com/neitanod/forceutf8

so as i understand my composer.json looks like this

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "forceutf8/forceutf8": "master"
    }
}

Bt for some reason (as i think forceutf8 has no version) its halts with error, all the rest installed correctly, error i get is

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package forceutf8/forceutf8 could not be found in any version, there may be a typo in the package na
me.

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://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. 

i tried following version also but no luck still

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "name": "career/skillquest",
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/neitanod/forceutf8"
      }
    ],
    "require": 
      {
        "forceutf8/forceutf8": "dev-master",
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16"
      }
}

Issue was it needs to be

"neitanod/forceutf8": "dev-master"

NOT

"forceutf8/forceutf8": "master"

回答1:


In composer.json:

{
    "name": "example/example-app",
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/neitanod/forceutf8"
      }
    ],
    "require": 
      {
        "neitanod/forceutf8": "dev-master",
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16"
      }
}



回答2:


First of all, you have the wrong name: forceutf8/forceutf8 Correct name is: neitanod/forceutf8

Composer adds a prefix of "dev-" to every branch name that is not looking like a version number, and a suffix "-dev" to branch names that look like version numbers.

Example: Branch "master" is called "dev-master", branch "feature" is called "dev-feature". Branch "1.0.x" is called "1.0.x-dev".

So this part is wrong:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "forceutf8/forceutf8": "master"
}

Correct version would be:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "neitanod/forceutf8": "dev-master"
}

Now requiring branches without tagged versions is not the best thing because these info is quite unstable - any new commit can break things, and it is not that easy to point exactly at the commit you wanted to use. To protect you agains this, Composer by default does not load these development branch, but will only load stable versions. You have to enable loading development versions:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "neitanod/forceutf8": "dev-master@dev"
}

The "@dev" flag allows to load development versions of the version mentioned (which in this case is a branch, but "1.0.0@dev" would work the same way, allowing all (including dev) versions of 1.0.0, like "1.0.0-alpha", but also the stable "1.0.0").

Note that you could also allow development version for ALL your dependencies by using "minimum-stability", but this is not recommended, because it will load development versions for EVERYTHING according to the version requirement. In your case, you would grab the latest dev version of monolog's 1.7 branch only, but this might be enough to bring a once stable software into a broken state.




回答3:


It's simple! You should type on console:

composer require blablabla@thepackage dev-master



回答4:


You have to specify the version name in the composer.json file. Just find any package which are installable with Composer at : https://packagist.org/

Search the package name there, you will find the version name. And here is the link for the package you wanted : https://packagist.org/packages/neitanod/forceutf8



来源:https://stackoverflow.com/questions/21694497/how-do-i-use-composer-to-install-a-package-without-a-version-only-master

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