Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 549
Alessandro Ronchi Avatar asked Apr 21 '16 12:04

Alessandro Ronchi


1 Answers

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 :)

like image 103
Seldaek Avatar answered Nov 15 '22 23:11

Seldaek