Composer/Laravel:如何添加/更新特定包

32
如何使用Composer添加/更新特定的软件包?我正在使用最新的Laravel,不确定是否有影响,但任何可以帮助确定答案的东西都可以。
我还尝试了一下来自旧的Stackoverflow帖子的以下内容,但对我没有用。它将软件包附加到composer.json,然后继续更新所有内容。这是链接:如何使用Composer更新单个库? 这是我尝试添加到我的项目中的软件包:https://github.com/barryvdh/laravel-dompdf 非常感谢您的时间和帮助!
编辑:

Require 和 update 都无法正常工作,它们会更新所有内容。我是否在错误的命令下运行了它们?当涉及到 composer 时,我还是个新手 :S

$ composer require barryvdh/laravel-dompdf
lease provide a version constraint for the barryvdh/laravel-dompdf requirement: *
/composer.json has been updated
oading composer repositories with package information
pdating dependencies (including require-dev)
 - Removing orchestra/testbench (v2.1.1)
 - Removing symfony/security (v2.4.3)
 - Removing symfony/translation (v2.4.3)
 - Installing symfony/translation (v2.4.6)
   Loading from cache

 - Removing symfony/http-foundation (v2.4.3)
 - Installing symfony/http-foundation (v2.4.6)
   Loading from cache

 - Removing symfony/event-dispatcher (v2.4.3)
 - Installing symfony/event-dispatcher (v2.5.0)
   Loading from cache

 - Removing symfony/debug (v2.4.3)
 - Installing symfony/debug (v2.4.6)
   Loading from cache

 - Removing symfony/http-kernel (v2.4.3)
 - Installing symfony/http-kernel (v2.4.6)
   Loading from cache

 - Removing symfony/routing (v2.4.3)
 - Installing symfony/routing (v2.4.6)
   Loading from cache

 - Removing symfony/process (v2.4.3)
 - Installing symfony/process (v2.4.6)
   Loading from cache

 - Removing symfony/finder (v2.4.3)
 - Installing symfony/finder (v2.4.6)
   Loading from cache

 - Removing symfony/dom-crawler (v2.4.3)
 - Installing symfony/dom-crawler (v2.4.6)
   Loading from cache

 - Removing symfony/css-selector (v2.4.3)
 - Installing symfony/css-selector (v2.4.6)
   Loading from cache

 - Removing symfony/console (v2.4.3)
 - Installing symfony/console (v2.4.6)
   Loading from cache

 - Removing symfony/browser-kit (v2.4.3)
 - Installing symfony/browser-kit (v2.4.6)
   Loading from cache

 - Removing swiftmailer/swiftmailer (v5.1.0)
 - Installing swiftmailer/swiftmailer (v5.2.0)
   Loading from cache

 - Removing stack/builder (v1.0.1)
 - Installing stack/builder (v1.0.2)
   Loading from cache

  - Removing patchwork/utf8 (v1.1.21)
  - Installing patchwork/utf8 (v1.1.23)
    Loading from cache

  - Removing nesbot/carbon (1.8.0)
  - Installing nesbot/carbon (1.9.0)
    Loading from cache

  - Removing monolog/monolog (1.9.0)
  - Installing monolog/monolog (1.10.0)
    Loading from cache

  - Removing symfony/filesystem (v2.4.3)
  - Installing symfony/filesystem (v2.5.0)
    Loading from cache

  - Installing symfony/security-core (v2.4.6)
    Loading from cache

  - Removing laravel/framework (v4.1.28)
  - Installing laravel/framework (v4.1.30)
    Loading from cache

  - Removing chumper/datatable (2.2.2)
  - Installing chumper/datatable (2.3)
    Loading from cache

  - Removing ivaynberg/select2 (3.4.6)
  - Installing ivaynberg/select2 (3.4.8)
    Loading from cache

  - Installing phenx/php-font-lib (0.2.2)
    Loading from cache

  - Installing dompdf/dompdf (v0.6.1)
    Loading from cache

  - Installing barryvdh/laravel-dompdf (v0.3.1)
    Loading from cache

symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
Generating autoload files
Compiling component files
Generating optimized class loader

你想仅更新单个软件包的原因是什么? - SUB0DH
1
是的,我不想更新所有内容,因为各种包可能已经发生了更改,这可能会破坏 Web 应用程序,所以我不想冒任何风险。我可能只需在另一个目录中安装 Composer 并添加所需的包,然后将其转移到我的主应用程序中的供应商。 - adamj
3个回答

37

我尝试了以下方法,对我而言似乎有效。

你需要首先将barryvdh/laravel-dompdf添加到composer.json文件中。之后执行以下步骤:

 composer update barryvdh/laravel-dompdf --lock

我已经尝试了 composer requirecomposer update,但每次运行它们时都没有成功,它们总是再次更新所有内容。我已经为您粘贴了一个屏幕截图,请您查看并指出我所犯的愚蠢错误。 - adamj
1
我已经更改了答案,使用了对我有效的方法。 - SUB0DH
我刚刚尝试了在末尾添加 --lock,但它仍然会再次更新所有内容。我想知道是否因为包的作者建议将其添加到 composer 中,如下所示 "barryvdh/laravel-dompdf": "*" ,如果未指定版本号,composer 命令是否必须更改?即 composer update "barryvdh/laravel-dompdf":"*" --lock。很抱歉,我不熟悉 composer ,所以不确定自己需要做什么,请原谅我的愚蠢。顺便说一下,非常感谢您的帮助! - adamj
使用版本1.6.3的Composer对我来说确实有效。但是,如果更新的软件包本身有一些要求,则可能会有副作用。Composer会引入新的要求(更新)。我不确定现有的要求会发生什么情况,例如那些与其他库或应用程序共享的要求。也许这也会导致更新。据我所知,这并没有记录在文档中。 - twigmac

9

2
如果你这样做,composer update 将会更新 所有 的东西,这就是 OP 所问的,而不是如何安装库。 - Damien Pirsy
谢谢0xshalaby,请查看上面的帖子并发表评论,因为我在使用requireupdate时没有太多的运气:( - adamj

0

以上的解决方案对我没有用,但如果还有人遇到这个问题

composer require <package> --no-update

当我添加一个包时,这对我很有效


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接