kskaradzinski
kskaradzinski

Reputation: 5084

Git private repository

When I use this

{
    "type": "package",
    "package": {
        "name": "name/vendor",
        "version": "dev-master",
        "source": {
            "url": "[email protected]:name/vendor.git",
            "type": "git",
            "reference": "master"
        }
    }
}

my autoload_psr4.php file is not generated with path I declare in my repository, but when I use the following configuration, it works ok.

{
    "type": "vcs",
    "url": "[email protected]:name/vendor.git"
}

I want to know why the first configuration generates the composer autoload files correctly, but the second configuration does not.

Edit 2:

Running composer update with the first configuration results in the following autoloads:

return array(
    'Symfony\\Bundle\\MonologBundle\\' => array($vendorDir . '/symfony/monolog-bundle'),
    'Symfony\\Bundle\\AsseticBundle\\' => array($vendorDir . '/symfony/assetic-bundle'),
    'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
);

When I changed to the second configuration, the autoload has:

return array(
    'skowronline\\TaskBundle\\' => array($vendorDir . '/skowronline/taskbundle'),
    'Symfony\\Bundle\\MonologBundle\\' => array($vendorDir . '/symfony/monolog-bundle'),
    'Symfony\\Bundle\\AsseticBundle\\' => array($vendorDir . '/symfony/assetic-bundle'),
    'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
);

I hope this is more clear.

Solution: https://getcomposer.org/doc/04-schema.md#repositories

Repository declarations of dependencies' composer.jsons are ignored.

Upvotes: 1

Views: 96

Answers (1)

Justin Howard
Justin Howard

Reputation: 5643

When you use the first configuration with type package, you are telling composer to override the composer.json in [email protected]:name/vendor.git. The autoload parameter will never be read. You can fix this by doing:

{
    "type": "package",
    "package": {
        "name": "name/vendor",
        "version": "dev-master",
        "source": {
            "url": "[email protected]:name/vendor.git",
            "type": "git",
            "reference": "master"
        },
        "autoload": {
            "psr-4": {<your autoload config>}
        }
    }
}

When you use the second configuration, all you are doing is telling composer to look in [email protected]:name/vendor.git before downloading from packagist. In this case, composer will read the composer.json from the repository including the autoload settings.

The second configuration is the preferred way. When you use a package declaration like in your first example, you are overriding the package author's original configuration. Don't do this unless you have a good reason.

Upvotes: 1

Related Questions