Composer - 从私有git存储库安装依赖项

时间:2014-07-02 17:32:59

标签: composer-php

我在私人GitHub帐户上有两个项目 - 一个是图书馆,另一个是我的应用程序。

我想将我的库包含在我的应用程序中。

我的图书馆的composer.json看起来像这样:

{
  "name": "andyw/mylibrary",
  "description": "My Library",
  "license": "proprietary",
  "homepage": "https://github.com/andyw/mylibrary",
  "require": {
    "php": ">=5.5.0",
    "monolog/monolog": "1.*",
    "guzzle/guzzle": "3.*",
    "aws/aws-sdk-php": "2.*",
    "nixilla/twitter-api-consumer": "*",
    "webignition/robots-txt-file": "dev-master",
    "webignition/robots-txt-parser": "dev-master",
    "pusher/pusher-php-server": "*",
    "symfony/validator": "2.*"
  },
  "require-dev": {
    "phpunit/phpunit": "3.*"
  },
  "autoload": {
    "psr-0": {
      "": "src/"
    }
  }
}

在该项目上运行composer update可以很好地安装依赖项。到目前为止,非常好。

现在这是我的应用程序的composer.json:

{
  "name": "andyw/myapp",
  "type": "project",
  "description": "My application",

  "homepage": "https://github.com/andyw/myapplication",
  "license": "proprietary",
  "repositories": [
    {
      "type": "git",
      "url": "git@github.com:andyw/myapplication.git"
    }
  ],
  "require": {
    "php": ">=5.5.0",
    "andyw/mylibrary": "dev-master",
    "facebook/php-sdk-v4": "4.0.*",
    "silex/silex": "~1.1",
    "monolog/monolog": "~1.6",
    "twig/twig": "~1.14",
    "doctrine/dbal": "~2.4",
    "nesbot/Carbon": "~1.6",
    "aws/aws-sdk-php": "2.*",
    "jms/serializer": "0.15",
    "symfony/validator": "2.*",
    "jdesrosiers/silex-cors-provider": "~0.1.2",
    "swiftmailer/swiftmailer": ">=4.1.2,<4.2-dev",
    "fzaninotto/faker": "~1.4"
  },
  "require-dev": {
    "mockery/mockery": "~0.8.0"
  },
  "autoload": {
    "psr-0": {
      "App": "src/"
    }
  }
}

在该项目上运行composer update失败。添加--verbose标志会显示此输出:

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

  Problem 1
    - Installation request for andyw/mylibrary dev-master -> satisfiable by andyw/mylibrary[dev-master].
    - andyw/mylibrary dev-master requires webignition/robots-txt-file dev-master -> no matching package found.

如果mylibrary可以安装webignition/robots-txt-file dev-master,为什么不能将它安装为依赖项的依赖项?我该如何解决这个问题?

仅供参考:我的所有回购均不公开,并且出于隐私原因,我已更改了我的包裹/文件的名称。

1 个答案:

答案 0 :(得分:0)

永远不要永远不要依赖树枝!始终使用标记版本。这是使用Composer时最重要的规则。

分支机构正在移动目标。如果有人提交新内容,这会将指针移动到您正在使用的软件状态,并且您无法再轻松找到此状态。此外,分支被认为是开发稳定性,唯一可以设置稳定性的包是根应用程序包。依赖于开发稳定性中的其他包的库是一个非常糟糕的主意,因为它们迫使根应用程序明确允许开发稳定性。

从长远来看,这是非常糟糕的。这将使您的软件无法维持到使用Composer总是失败,破坏东西,并开始想知道为什么每个人都在使用它的时候(提示:它们不依赖于分支)。

现在就是这样:

webignition / robots-txt-file具有标记版本:0.1和0.2,并且0.2与主分支完全相同。只需使用它!

webignition / robots-txt-parser也是如此,但这里有版本1.0,1.0.1和1.0.2,主分支正好是版本1.0.2。

您应该可以简单地更新到这些版本。如果这不起作用,因为你的软件依赖于旧版本的主分支,你在依赖分支时遇到了确切的问题:你的库告诉我dev-master是好的,当我查看软件包的repo时, dev-master分别是版本0.2或1.0.2,我希望它可以工作。如果你明确指出像0.1和1.0.1这样的东西,这不太可能随着时间而改变,并且永远是一个有效的组合。

请注意,检查外部程序包开发人员是否使用语义版本控制,然后对版本范围使用适当的通配符选择器是个好主意。允许版本中的一些松弛将使得多个包依赖于相同的第三个包来更容易地就共同版本达成一致。

相关问题