简体   繁体   中英

What is the meaning of “version” field in composer.json?

In the composer.json it is possible to specify a "version" field; here is an example:

{
    "name": "vendor/dummy_package",
    "description": "Dummy package",
    "version": "1.0.0"
}

Which is the meaning of this field since it doesn't seem to be mandatory?

Is it used to compare required versions of the vendor/dummy_package ?

In that case, does it win over tag?

Thank you!

The version is necessary for Composer to resolve the package as a dependecy. However, in most cases (and 100% of the time on packagist) the version is taken from the tags and branches in the repository.

In those cases, if the version is present in the composer.json, for branches it will be ignored, but for tags it MUST match the tag name, otherwise composer will consider that tag invalid as it has conflicting version information. Due to this we typically recommend that people leave the version out entirely as it reduces the chances for problems.

In a few cases like if you want to use the artifact repository for example, you need to specify the version in composer.json.

To sum up: If you don't know that you need it in, then leave it out :)

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