Composer騷操作,使用本地git目錄作為依賴解決衝突

抄你碼科技有限公司發表於2022-01-05

最近在用laravel 8.x測試easywechat: ^6.0-beta8時踩了不少坑,一本正經的debug了幾天後發現一些坑已經在master分支填完了,所以想著同步升級到最新的6.0-beta10繼續踩坑,但是發現從6.0-beta9開始 @overture 超哥光明正大的把一些依賴改成了更高的版本,但是我的laravel即使升級到最新版的8.78.0,composer update-W也一直提示依賴衝突呀,那就無法安裝,無法繼續踩坑了。。。

執行環境:
PHP 8.0.13
Composer version 2.1.11
Laravel Framework 8.78.0

執行以下命令:

$ composer require "w7corp/easywechat: ^6.0-beta10"  
./composer.json has been updated

Running composer update w7corp/easywechat

Loading composer repositories with package information

Updating dependencies

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

 Problem 1

 - Root composer.json requires w7corp/easywechat ^6.0-beta10 -> satisfiable by w7corp/easywechat[6.0-beta10].

 - w7corp/easywechat 6.0-beta10 requires symfony/http-foundation ^6.0 -> found symfony/http-foundation[v6.0.0-BETA1, ..., 6.1.x-dev] but the package is fixed to v5.4.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Composer騷操作,使用本地git目錄作為依賴解決衝突

$ composer require "w7corp/easywechat: ^6.0-beta9" 
./composer.json has been updated
Running composer update w7corp/easywechat
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - w7corp/easywechat[6.0-beta9, ..., 6.0-beta10] require symfony/http-foundation ^6.0 -> found symfony/http-foundation[v6.0.0-BETA1, ..., 6.1.x-dev] but the package is fixed to v5.4.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires w7corp/easywechat  ^6.0-beta9 -> satisfiable by w7corp/easywechat[6.0-beta9, 6.0-beta10].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Composer騷操作,使用本地git目錄作為依賴解決衝突

$ composer require "w7corp/easywechat: ^6.0-beta9" -W
./composer.json has been updated
Running composer update w7corp/easywechat --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
 Problem 1
 - laravel/framework is locked to version v8.78.0 and an update of this package was not requested.
 - Conclusion: don't install symfony/http-foundation v5.4.0-RC1 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v6.0.0-RC1 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v5.4.0 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v6.0.0 (conflict analysis result)
 - Conclusion: don't install one of symfony/http-foundation[v5.4.1], overtrue/socialite[4.0.0] (conflict analysis result)
 - Conclusion: install overtrue/socialite 4.0.0 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v5.4.2 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v6.0.1 (conflict analysis result)
 - Conclusion: don't install symfony/http-foundation v6.0.2 (conflict analysis result)
 - facade/ignition is locked to version 2.17.4 and an update of this package was not requested.
 - Root composer.json requires w7corp/easywechat ^6.0-beta9 -> satisfiable by w7corp/easywechat[6.0-beta9, 6.0-beta10].
 - overtrue/socialite 4.0.0 requires symfony/http-foundation ^6.0 -> satisfiable by symfony/http-foundation[v6.0.0-BETA1, ..., 6.1.x-dev].
 - You can only install one version of a package, so only one of these can be installed: symfony/http-foundation[v2.7.0-BETA1, ..., 2.8.x-dev, v3.0.0-BETA1, ..., 3.4.x-dev, v4.0.0-BETA1, ..., 4.4.x-dev, v5.0.0-BETA1, ..., 5.4.x-dev, v6.0.0-BETA1, ..., 6.1.x-dev].
 - laravel/framework v8.78.0 requires symfony/http-foundation ^5.4 -> satisfiable by symfony/http-foundation[v5.4.0-BETA1, ..., 5.4.x-dev].
 - Conclusion: don't install symfony/http-foundation 5.4.x-dev (conflict analysis result)
Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Composer騷操作,使用本地git目錄作為依賴解決衝突

好吧,不想等laravel9.x。。那就度娘谷哥一下。。找到了這篇 composer引用本地git做為源庫發現可以搞定,那就擼一把。。

一、倉庫克隆到本地進行魔改

  1. git clone到本地,魔改下master分支的composer.json

    $ git clone https://github.com/w7corp/easywechat.git

    Composer騷操作,使用本地git目錄作為依賴解決衝突

  2. 在本地git上建立分支commit,打上自己心儀的tag,如6.0.1-beta10
    Composer騷操作,使用本地git目錄作為依賴解決衝突

二、 修改laravel專案的 composer.json

  1. 新增repositories屬性,排除源easywechat包和新增本地的easywechat git目錄
{
 "name": "laravel/laravel",
 "type": "project",
 "description": "The Laravel Framework.",
 "keywords": ["framework", "laravel"],
 "license": "MIT",
 // 新增repositories屬性
 "repositories": [
     // composer源排除指定的包 [可選],不排除貌似不影響。
     {
         "type": "composer",
         "url": "https://mirrors.aliyun.com/composer",
         "exclude": ["w7corp/easywechat"] //從composer源排除掉指定的包
     },
     // 重點加上以下這個
     {
         "type": "git",
         "url": "/你本地目錄/easywechat-git" // 新增本地git地址或遠端git地址
     }
 ],
 "require": {
     // 以下省略一大堆不重要的內容
 },
 // 以下省略一大堆不重要的內容
}
  1. $ composer require "w7corp/easywechat: ^6.0.1-beta10"
    % composer require "w7corp/easywechat: ^6.0.1-beta10"
    ./composer.json has been updated
    Running composer update w7corp/easywechat
    Loading composer repositories with package information
    Updating dependencies                                 
    Lock file operations: 12 installs, 0 updates, 0 removals
    - Locking nyholm/psr7 (1.4.1)
    - Locking nyholm/psr7-server (1.0.2)
    - Locking overtrue/socialite (3.5.0)
    - Locking php-http/message-factory (v1.0.2)
    - Locking psr/cache (2.0.0)
    - Locking symfony/cache (v5.4.2)
    - Locking symfony/cache-contracts (v2.5.0)
    - Locking symfony/http-client (v5.4.2)
    - Locking symfony/http-client-contracts (v2.5.0)
    - Locking symfony/psr-http-message-bridge (v2.1.2)
    - Locking symfony/var-exporter (v6.0.0)
    - Locking w7corp/easywechat (6.0.1-beta10)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 12 installs, 0 updates, 0 removals
    - Downloading symfony/http-client (v5.4.2)
    - Downloading symfony/cache (v5.4.2)
    - Syncing w7corp/easywechat (6.0.1-beta10) into cache
    0/2 [>---------------------------]   0%    Failed downloading symfony/http-client, trying the next URL (404: The "https://mirrors.aliyun.com/composer/dists/symfony/http-client/5e344f1402584a56631c81a24ec9403e3159c790.zip" file could not be downloaded (HTTP/2 404 ))
    1/2 [==============>-------------]  50%    Failed downloading symfony/cache, trying the next URL (404: The "https://mirrors.aliyun.com/composer/dists/symfony/cache/8aad4b69a10c5c51ab54672e78995860f5e447ec.zip" file could not be downloaded (HTTP/2 404 ))
    - Installing php-http/message-factory (v1.0.2): Extracting archive
    - Installing psr/cache (2.0.0): Extracting archive
    - Installing symfony/cache-contracts (v2.5.0): Extracting archive
    - Installing symfony/http-client-contracts (v2.5.0): Extracting archive
    - Installing symfony/var-exporter (v6.0.0): Extracting archive
    - Installing symfony/psr-http-message-bridge (v2.1.2): Extracting archive
    - Installing symfony/http-client (v5.4.2): Extracting archive
    - Installing symfony/cache (v5.4.2): Extracting archive
    - Installing overtrue/socialite (3.5.0): Extracting archive
    - Installing nyholm/psr7-server (1.0.2): Extracting archive
    - Installing nyholm/psr7 (1.4.1): Extracting archive
    - Installing w7corp/easywechat (6.0.1-beta10): Cloning 4064a7a14c from cache
    Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
    Generating optimized autoload files
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
    > @php artisan package:discover --ansi
    Discovered Package: facade/ignition
    Discovered Package: fruitcake/laravel-cors
    Discovered Package: laravel/sail
    Discovered Package: laravel/sanctum
    Discovered Package: laravel/tinker
    Discovered Package: nesbot/carbon
    Discovered Package: nunomaduro/collision
    Package manifest generated successfully.
    86 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    > @php artisan vendor:publish --tag=laravel-assets --ansi --force
    No publishable resources for tag [laravel-assets].
    Publishing complete.
  2. 喔呵~搞定,繼續踩坑

引用:
www.cnblogs.com/xuezhigu/p/6769498...

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章