Kwadz
Kwadz

Reputation: 2232

How to force Composer to download a local package?

Let's say we have the following directory structure, we assume my-package also exists on Packagist:

- apps
\_ my-app
  \_ composer.json
- packages
\_ my-package
  \_ composer.json

To add my/package as a dependency of my-app, the documentation states we can use the following configuration:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "*"
    }
}

However when I composer update, the dependency is still downloaded from Packagist. So, to see, I disabled Packagist.org:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package",
            "packagist.org": false
        }
    ],
    "require": {
        "my/package": "*"
    }
}

I cleared the cache with composer clearcache, removed my/package with composer remove my/package and installed it again with composer require my/package --prefer-source (I didn't understand if --prefer-source is for vcs only). The downloaded package is still not the local one. How to force composer to use the local one?

Upvotes: 12

Views: 6725

Answers (2)

oshaiken
oshaiken

Reputation: 2650

For

composer --version
Composer version 2.0.14 

in composer.json file

"require": {
"my/package": "dev-master"
}

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

"require": {
    "my/package": "*"
}

In case of VCS or path repository types, you need to specify version of the package you request. So instead of using *, as you have currently, use @dev:

"require": {
    "my/package": "@dev"
}

Upvotes: 13

Related Questions