Composer骚操作,使用本地git目录作为依赖解决冲突

前言

最近在用laravel 8.x测试easywechat: ^6.0-beta8时踩了不少坑,一本正经的debug了几天后发现一些坑已经在master分支填完了,所以想着同步升级到最新的6.0-beta10继续踩坑,但是发现从6.0-beta9开始 @overture 超哥光明正大的把一些依赖改成了更高的版本,但是我的laravel即使升级到最新版的8.78.0,composer update-W也一直提示依赖冲突呀,那就无法安装,无法继续踩坑了。。。

案情重现:composer依赖冲突的提示

运行环境:
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 协议》,转载必须注明作者和本文链接
CV专员在静静的抄你码
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 3

这是开发 composer 包的必备技能啊

2年前 评论

你肯定没买@overtrue 大佬的扩展包开发教程测试我们的扩展包《LX2 PHP 扩展包实战教程 - 从入门到发布》

2年前 评论
抄你码科技有限公司 (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!