Composerで依存パッケージのcomposer.lockは使われるのか?
rootのcomposer.lockにバージョンが記載されていれば、composer installした場合は、その記載バージョンのパッケージがインストールされます。
では、依存パッケージにcomposer.lockがある場合は、どうなるのでしょう?
確認してみましょう。
現在、Ray.Diにはcomposer.lockが含まれています。そして、doctrine/annotationsのバージョンがv1.2.1になっています。
検証方法
まず、フォルダを作成し、rootのcomposer.jsonを作成します。
{
"require": {
"ray/di": "~2.0@dev"
},
"minimum-stability": "dev",
"prefer-stable": true
}
composer installします。
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing nikic/php-parser (v1.0.2)
Loading from cache
- Installing doctrine/lexer (v1.0)
Loading from cache
- Installing doctrine/annotations (v1.2.3)
Loading from cache
- Installing ray/aop (2.0.0-alpha)
Loading from cache
- Installing ray/di (dev-develop-2 92cd0e3)
Cloning 92cd0e3d1f2feb8dbaaed7350e2f55d5af9a2a96
Writing lock file
Generating autoload files
上記のようにdoctrine/annotationsはv1.2.1ではなくv1.2.3がインストールされました。
結論としては、依存パッケージのcomposer.lockは使われないということになるようです。
ライブラリ(公開するパッケージ)にcomposer.lockを含めるかどうか?
(14:02 追記)
Composerの公式ドキュメントにちゃんと書いてありました。
For your library you may commit the composer.lock file if you want to. This can help your team to always test against the same dependency versions. However, this lock file will not have any effect on other projects that depend on it. It only has an effect on the main project.
-- https://getcomposer.org/doc/02-libraries.md#lock-file
まとめると、
- ライブラリには
composer.lockを含めたい場合は含めてもいい - そうすれば、そのライブラリの開発チームはいつも同じ依存バージョンを使いテストすることができる(
composer installすれば) - しかし、そのライブラリを使用するプロジェクト(アプリケーション)には影響しない(上で見たように
composer.lockは使われないため) composer.lockはメインプロジェクト(rootにある場合)にしか影響しない
結論としては、composer.lockは含めても含めなくてもどっちでもいいみたいですね。
関連
Date: 2014/12/30



![徹底攻略PHP5技術者認定[上級]試験問題集 [PJ0-200]対応 徹底攻略PHP5技術者認定[上級]試験問題集 [PJ0-200]対応](http://tatsu-zine.com/images/books/164/cover_s.jpg)

