Featured image of post 依存関係でcomposerのインストールがうまく行かなかった場合の対処法

依存関係でcomposerのインストールがうまく行かなかった場合の対処法

Twitter ツイート Hatena Bookmark ブックマーク

こんばんは、最近またSymfony2やcomposerに触れる機会が増えてきた僕です。
さて、今日はcomposerでinstallやupdateしたら、ライブラリがメンテされてなくて依存関係でインストール出来なかった時の対処法をお教えします。

phpforce/salesforce-bundleをインストールしようとしたら、composerでこけたんですね。
原因としては、phpforce/salesforce-bundleのcomposer.jsonの中で、phpforce/soap-clientを指定してたんですが、そのphpforce/soap-clientのcomposer.jsonで指定してたdoctrine/commonの値が「2.3@stable」になってたからぽいです。

さらに、phpforce/soap-clientのcomposer.jsonでphpforce/commonが指定されているんですが、そのphpforce/commonのcomposer.jsonで symfony/event-dispatcher: >=2.1@stable指定されているからもう。。。。。

で、Symfony2.4 or 2.3の環境でインストールしようとするとエラーになりますね。つまりSymfony2.1じゃないとだめぽみたいな。。。
「satisfiable by phpforce/soap-client」みたいなメッセージが・・・

まあ今回みたいな事って大composeer時代となったら、多々あると思います。
で、今回の場合はどうしたのかってことですが、まあpull requestは送るのは当然だと思いますが、とりあず動かすために、ひたすら問題のあるライブラリをフォークして、直すってことをしました。

さらにこちらで使用するcomposer.jsonのrepositoriesで、forkしたgithubのリポジトリを指定するようなアプローチを行いました。

フォークしたライブラリ

https://github.com/polidog/common/tree/composer_edit
https://github.com/polidog/soap-client/tree/composer

フォークした二つのライブラリはcomposer.jsonの中身を変更しています。

フォークしたライブラリを利用するcomoposer.jsonの書き方

ポイントとしては2つあります。
1つ目は、repositoriesの部分ですね。
ここにフォークしたgithubのurlを貼付けましょう。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/polidog/soap-client"
        },
        {
            "type": "vcs",
            "url": "https://github.com/polidog/common"
        }
    ],

2つ目は、通常であればrequireのしていには「”phpforce/salesforce-bundle”: “dev-master”」だけ記載すればいいのですが、forkしたphpforce/commonとphpforce/soap-clientを指定します。

1
2
3
4
5
"require": {
...
        "phpforce/common": "dev-composer_edit",
        "phpforce/soap-client": "dev-composer_edit",
        "phpforce/salesforce-bundle": "dev-master",

全体としては、こんな感じっす。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/polidog/soap-client"
        },
        {
            "type": "vcs",
            "url": "https://github.com/polidog/common"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~2.3",
        "sensio/framework-extra-bundle": "~3.0",
        "sensio/generator-bundle": "~2.3",
        "incenteev/composer-parameter-handler": "~2.0",

        "phpforce/common": "dev-composer_edit",
        "phpforce/soap-client": "dev-composer_edit",
        "phpforce/salesforce-bundle": "dev-master",

        "guzzle/http": "v3.7.4"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.4-dev"
        }
    }
}

最後に

修正した箇所を、pull requestを送ったらちゃんとマージされてました!
https://github.com/phpforce/soap-client/pull/8
https://github.com/phpforce/common/pull/1

なので、今からphpforce/salesforce-bundleをSymfony2.4でインストールするならcomposer.jsonのrequireはphpforce/salesforce-bundleだけで大丈夫です。さらにrepositoriesの記述もいらないです。
以下のようにcomposer.json書けばいいと思います。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~2.3",
        "sensio/framework-extra-bundle": "~3.0",
        "sensio/generator-bundle": "~2.3",
        "incenteev/composer-parameter-handler": "~2.0",
        "phpforce/salesforce-bundle": "dev-master",
        "guzzle/http": "v3.7.4"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.4-dev"
        }
    }
}

最後の最後に、、、

業務中にpull request送ってごめんなさい・・・だってライブラリ1から作るのめんどくさいし工数掛かっちゃうんだもん・・・(´・ω・`)

comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。