简体   繁体   中英

How do I specify Composer package stability?

I have a git repository on Bitbucket, which is a Composer-enabled package (containing a composer.json that looks like this):

{
    "name": "foo/package",
    "version": "0.0.1"
}

I have another project that has this composer.json:

{
    "name": "foo/project",
    "repositories": [
        {
            "type": "vcs",
            "url": "[bitbucket git url]",
        }
    ],
    "require": {
         "foo/package": "*"
    }
}

If I try to run composer install , I get an error message:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for foo/package * -> satisfiable by foo/package[dev-master].
    - Removal request for foo/package == 9999999-dev

If I add the following line to the project's composer.json, the error goes away and the package installs properly.

"minimum-stability": "dev"

I understand that Composer does not consider foo/package to be stable, which is why it says it can't find it, and adding the "minimum-stability" line tells it that foo/package is okay to install. But I don't know how to tell Composer that foo/package is stable.

Setting the required version to 0.0.1 instead of * does not work either, it just gives me this error instead:

 Problem 1
- The requested package stashimi/crawler 0.0.1 could not be found.

I found another Stack Overflow question which implies that giving foo/package a version number will indicate that it's stable, but this obviously isn't working, given the files above. What am I doing wrong?

Okay, I figured out my own problem. Basically, when using a VCS repository, it looks for a tag with the given requirement version. In my case, since there was no tag 0.0.1 in my repo, Composer couldn't find it. Creating that tag in the repo solved the problem.

The other (probably more correct) way to solve this is to make the required version dev-master , which basically means "use the master branch in the repository." (Or whatever branch; Composer's documentation about the dev-X version specification is a bit confusing.)

The only way to create a stable version is to tag it. It is a very good idea to use semantic versioning , which means that a really stable version starts at version 1.0.0. All zero-versions are considered experimental and unstable in semantic versioning, but Composer would consider these tag as stable. However, there is a difference between the tilde operator (which does not handle zero versions different) and the caret operator (which does).

Avoid relying on branches! It will break your software in the long run, because a branch does not point to one specific state of the software package, but to a work-in-progress that will change over time. It is a pain to work with, making it impossible to update anything in the end. Don't go that way!

And by the way: Using branches is "dev" stability, which will not work if you have a software requiring a package that requires a branch - you would have to allow dev stability in your main software, which is either "minimum-stability:dev" for ALL packages you use (even if you can "prefer-stable:true"), or you'd manually find out which dev-stable package is being used, and include this explicitly.

It's just too much hassle to do it. Tag your software, and you'd be fine, even if it isn't semantic.

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