问题
I am relatively new to Composer and have been looking for an example of using a local repository using the path repo type. I've found several articles (e.g. this one and this one on the topic, but when I try the examples I end up getting an error like:
The requested package myvendor/mylibrary could not be found in any version, there may be a typo in the package name.
So I thought I'd create a super-simple example of what I'm trying in hopes that someone can point me in the right direction.
My sample app is organised as such:
├── app1
│ └── composer.json
├── app2
│ └── composer.json
└── libraries
└── testlibrary
├── composer.json
├── TestService.php
Within libraries/testlibrary/composer.json
is the following:
{
"name": "myvendor/mylibrary",
"version": "dev-master"
}
And within each of the app folders (e.g. app1) the composer.json
file looks like this:
{
"repositories": [
{
"type": "path",
"url": "../libraries/testlibrary"
}
],
"require": {
"myvendor/mylibrary": "*"
}
}
If anyone has any suggestion for what I'm doing incorrectly, I'd be very appreciative!
回答1:
I found an answer here
Instead of this:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*"
}
}
You should write this:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "dev-master"
}
}
Note the change from *
to dev-master
in the require
section.
回答2:
Your setup looks correct. I use that solution as well. I think the problem lies elsewhere. Try changing *
constraint to something like dev-master
. If that doesn't solve it, please post your composer.json
from mylibrary
.
来源:https://stackoverflow.com/questions/37399842/how-to-use-path-type-local-repository-with-composer