M Tauqeer
M Tauqeer

Reputation: 408

composer always installs latest version of the package

I have made two new releases v1.0.0 and v0.2.0 of my package mailbase.

The v1.0.0 has package constraint ^7.0

"laravel/framework": "^7.0"

The v0.2.0 has package constraint

"laravel/framework": "^5.0|^6.0"

But when I install this package

composer require tkeer/mailbase

the composer always install v1.0.0 irrespective of laravel version (laravel5, laravel6 or laravel7). Shouldn't it install v0.2.0 for laravel6 and laravel5?

Upvotes: 2

Views: 2448

Answers (3)

Nico Haase
Nico Haase

Reputation: 12105

On running composer require tkeer/mailbase without any further version constraint, Composer computes which versions of that package are compatible with the other currently required packages. The latest possible version is installed.

In your example: if you already have Laravel v5 or v6 installed, the latest possible version of that package to be installed is v0.2.0, as v1.0.0 is compatible with Laravel v7 only. Likewise, if Laravel v7 is installed, v1.0.0 of your package is installed, as the prior version v0.2.0 is not compatible with Laravel v7.

If you use composer require tkeer/mailbase:"v1.0.0" while Laravel v5 or v6 is installed, an error message will be thrown, as this package is not compatible.

Upvotes: 1

Rudra
Rudra

Reputation: 714

composer always select latest version to install

here's syntax to install packages via composer

composer require vendor/package:version

specify version to install

composer require tkeer/mailbase:0.2.0

Upvotes: 1

Noaman Ahmed 99
Noaman Ahmed 99

Reputation: 71

Actually Your composer.json of plugin is telling this

V1.0.0 can only run on Laravel 7.0 and greater

v0.2.0 can run on all Laravel from 5.0 to 6.0 v0.2.0 can run on all Laravel from 6.0 to 7.0

Adding ^6.0 make is available from version 6.0 to 7.0

If I unable to explain this,please see this URL for more information

https://getcomposer.org/doc/articles/versions.md#writing-version-constraints

"require": {
    "vendor/package": "1.3.2", // exactly 1.3.2

    // >, <, >=, <= | specify upper / lower bounds
    "vendor/package": ">=1.3.2", // anything above or equal to 1.3.2
    "vendor/package": "<1.3.2", // anything below 1.3.2

    // * | wildcard
    "vendor/package": "1.3.*", // >=1.3.0 <1.4.0

    // ~ | allows last digit specified to go up
    "vendor/package": "~1.3.2", // >=1.3.2 <1.4.0
    "vendor/package": "~1.3", // >=1.3.0 <2.0.0

    // ^ | doesn't allow breaking changes (major version fixed - following semver)
    "vendor/package": "^1.3.2", // >=1.3.2 <2.0.0
    "vendor/package": "^0.3.2", // >=0.3.2 <0.4.0 // except if major version is 0
}

Upvotes: 2

Related Questions