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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With