I have created a private package at packagist.org under new organisation. Here are the steps i took so far:
Developed a lumen package at local instance.
Configured composer.json to be used with private composer package.
Pushed the local package to private github repo.
Added the package by URL at packagist.org and all the api token and credentials has also been setup.
The project get added without any error.
I have added the composer global auth token to require private package.
When i either search or require the package to new lumen instance i get the error
[InvalidArgumentException]
Could not find a matching version of package grv/contentfeed. Check the pac
kage spelling, your version constraint and that the package is available in
a stability which matches your minimum-stability (dev).
This is how my composer.json looks like:
{
"name": "grv/contentfeed",
"description": "This is yet another Lumen composer package wrapper",
"type": "elx-core-plugin",
"version": "1.2.3",
"keywords": ["demo","lumen","drupal"],
"homepage": "https://github.com/gauravmehrasrijan/elx-feed",
"require": {
"composer/installers": "^1.0.24"
},
"autoload": {
"psr-4": {
"Grv\\Contentfeed\\": "/src"
}
},
"license": "MIT",
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"Grv\\Contentfeed\\ContentFeedServiceProvider"
]
}
},
"authors": [
{
"name": "Gaurav Mehra",
"email": "gauravmehra1987#gmail.com"
}
],
"repositories": [
{"type": "composer", "url": "https://repo.packagist.com/grvatsrijan/"},
{"packagist.org": false}
]
}
Are there some more steps to it that i am missing. I have even tried creating new packages with different namespace but no success.
It turned out that i was adding this piece of code at wrong place.
"repositories": [
{"type": "composer", "url": "https://repo.packagist.com/grvatsrijan/"},
{"packagist.org": false}
]
Instead of adding it to created composer package, this will need to go in the consumer composer package( where i am trying to require this package ).
Adding "repositories" key to composer.json will allow composer to search for private package within the https://repo.packagist.com/grvatsrijan/
Related
Since composer merge plugin is deprecated and the alternative is use of composer path repositories I found a problem transitioning to the later.
My structure is:
/composer.json
/local/composer.json
Where /composer.json is main composer with all setup and /local/composer.json is a file managing only private repositories.
Contents of each file are:
#/composer.json
{
"name": "main/project",
"type": "project",
"repositories": [
{
"type": "path",
"url": "local"
}
],
"require": {
"sub/project": "dev-main"
},
"extra": {
"installer-paths": {
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
]
}
}
}
#/local/composer.json
{
"name": "sub/project",
"autoload": {},
"repositories": {
"test_repo": {
"type": "git",
"url": "git#github.com:rotari/test_repo.git"
}
},
"require": {
"rotari/test_repo": "dev-main"
}
}
As you can see the plan is simple: main composer requires sub/project and sub/project requires rotari/test_repo. However on install I'm prompted with error
sub/project dev-main requires rotari/test_repo dev-main -> could not be found in any version
Running composer install in /local is a success so there is no problem accessing rotari/test_repo.
Any idea or suggestions how this issue could be solved?
This part from documentation answers my quetion:
https://getcomposer.org/doc/faqs/why-cant-composer-load-repositories-recursively.md
Composer in not able to load repositories recursively.
I have some problem by using Composer to load a custom library from another custom library
I have 2 custom libraries called "ia/audit_trail" and "ia/flash". And "ia/audit_trail" needs "ia/flash" to work.
audit_trail : https://github.com/pierrererot/audit_trail
flash : https://github.com/pierrererot/flash
So, I have the require property set for calling another one. Nothing special, BUT, when I run a simple composer update -vvv in my main project, I got this error :
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for ia/audit_trail_component ~1.0.0 -> satisfiable by ia/audit_trail_component[1.0.0].
- ia/audit_trail_component 1.0.0 requires ia/flash_component ~1.0.0 -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details.
- It's a private package and you forgot to add a custom repository to find it
Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems...
BUT, if I put these two librairies directly into my main project (so if one librairy doesn't need another librairy), it works !.
Here is the composer.json of my main project :
{
"require": {
"ia/audit_trail_component": "1.0.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/pierrererot/audit_trail.git"
}
]
}
All right. So I did require my custom "audit_trail" library. So now, here is the composer.json of my custom "audit_trail" library :
{
"name": "ia/audit_trail_component",
"version": "1.0.0",
"type": "library",
"require": {
"ia/flash_component": "1.0.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/pierrererot/flash.git"
}
],
"minimum-stability": "dev"
}
All right. So I did require my custom "flash" library. And then, here is the composer.json of my custom "flash" library :
{
"name": "ia/flash_component",
"version": "1.0.0",
"description": "Flash Component",
"type": "library",
"minimum-stability": "dev"
}
As you can see, everything seems ok in my composer files, so I don't understand what I missed.
==> Does anyone have a clue please ?
Before you ask, I precise these things :
Both libraries have a "dev" and a "master" branch pushed on their Git repositories
Both libraries have a minimum 1.0.0 tag pushed on their Git repositories
repositories setting is root-only - Composer will ignore this setting for all dependencies and use only these repositories defined in your main project.
Repositories are only available to the root package and the repositories defined in your dependencies will not be loaded. Read the FAQ entry if you want to learn why.
https://getcomposer.org/doc/05-repositories.md#repository
So you need add all necessary repositories into composer.json of your main project:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/pierrererot/audit_trail.git"
},
{
"type": "vcs",
"url": "https://github.com/pierrererot/flash.git"
}
],
I have 2 packages on Packagist.
https://packagist.org/packages/erayalakese/envato-market-api (A)
https://packagist.org/packages/erayalakese/envato-update-checker (B)
B requires A.
Now I'm using B package on my projects. But I'm getting Class 'erayalakese\Envato_Update_Checker' (package B) not found error.
This is my composer.json file
{
"name": "",
"description": "",
"require": {
"erayalakese/envato-update-checker": "^1.3"
},
"authors": ...
}
And my project file:
<?php
require_once(__DIR__.'/vendor/autoload.php');
new erayalakese\Envato_Update_Checker(...);
When I add this to my composer.json as temporary solution, it's working :
"autoload": {
"classmap": ["vendor/"]
}
But I'm not sure I really need to add vendor folder to autoload . I was expecting it will autoload my vendors automatically.
Can you tell me what's I'm missing?
You have to change the composer.json of both packages.
Both packages need to define a autoload section.
Referencing: https://getcomposer.org/doc/04-schema.md#classmap
erayalakese/envato-market-api
https://github.com/erayalakese/envato-market-api/blob/master/composer.json
{
"name": "erayalakese/envato-market-api",
"description": "Envato Market API to verify and download Envato purchases",
"authors": [
{
"name": "Eray Alakese",
"email": "erayalakese#gmail.com"
}
],
"require": {},
"license": "GPL v2",
"autoload": {
"classmap": ["Envato_Market_API.php"]
}
}
Now this package has a autoload classmap definition, which consists of one PHP file. When you composer install, the autoload definition of the package will be added to the Composer Autoloader.
Same game for the other package:
erayalakese/envato-update-checker
https://github.com/erayalakese/envato-update-checker/blob/master/composer.json
{
"name": "erayalakese/envato-update-checker",
"description": "Checks Envato WordPress plugins' updates and download its if any update available",
"require": {
"erayalakese/envato-market-api": "^1.0"
},
"authors": [
{
"name": "Eray Alakese",
"email": "erayalakese#gmail.com"
}
],
"license": "GPL v2",
"autoload": {
"classmap": ["Envato_Update_Checker.php"]
}
}
In your main project:
require the "updater" package in the composer.json of your main project
the updater packages included the api package via it's require section (so you get both)
add require_once(__DIR__ . '/vendor/autoload.php'); to the project bootstrap
enjoy Class via Composers Autoloader: new erayalakese\Envato_Update_Checker(...);
Remove this line:
https://github.com/erayalakese/envato-update-checker/blob/master/Envato_Update_Checker.php#L11
I create a widget that is under development. The problem is that when I run:
composer require chofoteddy/yii2-bootstrap-wizard "*"
I get the following message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for chofoteddy/yii2-bootstrap-wizard * -> satisfiable by chofoteddy/yii2-bootstrap-wizard[dev-master].
- chofoteddy/yii2-bootstrap-wizard dev-master requires vinceg/twitter-bootstrap-wizard * -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
What I seek is to add https://github.com/VinceG/twitter-bootstrap-wizard.git repository as a dependency of my project. "VinceG/twitter-bootstrap-wizard" is not registered in "Packagist".
I modified many times my composer.json file, in order to correct it, but I can not make it work.
My file composer.json:
{
"name": "chofoteddy/yii2-bootstrap-wizard",
"description": "Wizard form based on twitter bootstrap plugin (#VinceG)",
"homepage": "https://github.com/Chofoteddy/yii2-bootstrap-wizard",
"keywords": [
"yii2",
"wizard",
"bootstrap",
"yii2-extension"
],
"type": "yii2-extension",
"version": "0.1",
"license": "MIT",
"authors": [
{
"name": "Christopher",
"email": "chofoteddy88#yahoo.com.mx"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"VinceG/twitter-bootstrap-wizard": "*"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/VinceG/twitter-bootstrap-wizard"
}
],
"autoload": {
"psr-4": {
"chofoteddy\\wizard\\": ""
}
}
}
Composer information:
sudo composer self-update
You are already using composer version b2173d28fc8b56236eddc8aa10dcda61471633ec.
Because VinceG/twitter-bootstrap-wizard is not a Composer package (it does not include a composer.json) you have to define this in your composer.json
Your repository section should look like this:
"repositories": [
{
"type": "package",
"package": {
"name": "VinceG/twitter-bootstrap-wizard",
"version": "1.2",
"dist": {
"url": "https://github.com/VinceG/twitter-bootstrap-wizard/archive/1.2.zip",
"type": "zip"
},
"source": {
"url": "https://github.com/VinceG/twitter-bootstrap-wizard.git",
"type": "git",
"reference": "1.2"
}
}
}
],
You might also have a look at component-installer and the composer-asset-plugin to manage components and bower packages within composer.
The problem is probably the minimum-stability defined in your project root composer.json (or if not defined it defaults to stable)
As the bower repository has no release yet you should:
"VinceG/twitter-bootstrap-wizard": "#dev"
define minimum-stability: "#dev"
Please note that if you use this package from a different project you need to either define minimum-stability: "#dev" in that project or define the
"VinceG/twitter-bootstrap-wizard": "#dev" in root composer.json
There's also an option in composer which lets you specify: "prefer-stable"
More info on this:
https://igor.io/2013/02/07/composer-stability-flags.html
This is my composer.json, I want to use Nodge's fork of lessphp project on Github
"repositories": [{
"type": "package",
"package": {
"version": "dev-master",
"name": "nodge/lessphp",
"source": {
"url": "https://github.com/Nodge/lessphp.git",
"type": "git",
"reference": "master"
},
"autoload": {
"classmap": ["lessc.inc.php"]
}
}
}],
"require": {
"php": ">=5.3.3",
"nodge/lessphp": "dev-master"
},
But I get this error when I run composer update:
nodge/lessphp dev-master -> no matching package found.
I don't know how to require correctly this fork.
The most common (and easiest) way of doing it is using a VCS repository.
All you have to do is add your fork as a repository and update the
version constraint to point to your custom branch. Your custom branch
name must be prefixed with dev-.
Assuming you forked monolog/monolog and created a branch called bugfix, you would update your composer.json like this:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/igorw/monolog"
}
],
"require": {
"monolog/monolog": "dev-bugfix"
}
}
Note that you don't change the require statement except to specify your bugfix branch. You still reference the upstream package (monolog/monolog), not your personal fork (igorw/monolog), and the branch name is prefixed with dev-. You can read details in the docs
Using VCS works:
"name": "test/test",
"repositories": [{
"type": "vcs",
"url": "http://github.com/Nodge/lessphp"
}],
"require": {
"leafo/lessphp": "dev-master"
},
But if I require a module that has this composer.json, it doesn't work. It installs the original project, not the fork.
Example
"name": "example/example",
"require": {
"test/test": "dev-master"
},
I should mention again the repository. Is that normal?
If you can't get #Neilime answer to work for you, make sure your fork uses a different branch.
For example push your changes to a branch on your fork called my-bugfix, do not added dev- prefix in your branch name but in your composer.json you have to add it. Your composer file will look like:
"repositories":
[
{
"type": "vcs",
"url": "http://github.com/yourname/packageName"
}
],
"require": {
"owner/packageName": "dev-my-bugfix"
},
I have tried many options but After I got this post I saw the light and it just worked perfect.
This is what you have to do:
1- Fork The repository
2- Create a branch and make the required modifications.
3- Add the repository label to your composer.json
"repositories": [
{
"type": "vcs",
"url": "https://github.com/user/yourforkname"
}
]
4- In the command line inside your project require your fork like this:
composer require vendor/packagename:dev-branchname
And Voilá!!
You have your fork version working
According to the Composer documentation
http://getcomposer.org/doc/05-repositories.md#vcs, it's enough to
specify the original repository (not the fork) in the require ("nodge/lessphp" in your case). Composer will then install YOUR fork (look at the code in the vendors)
So, this is 2019, and most of the answers here are already correct.
If you find yourself however, in a situation where you need to require a particular branch of your fork (that you created), have composer list the available versions/tags first.
This saved me a lot of time.
A full example with spatie/laravel-backup package.
First, add repositories key to composer.json. With the url of your fork
"repositories": [{
"type": "vcs",
"url": "https://github.com/holymp2006/laravel-backup"
}]
Get available versions/tags
composer show "spatie/laravel-backup" --all
Choose the version you want from versions in the terminal output, then require that version
composer require spatie/laravel-backup:v5.x-dev
I usually add a "dist" node to the package definition.
I never had a problem using it this way.
I can't remember where I got this trick from, though, for any further explanations.
{
"repositories": [
{
"type": "package",
"package": {
"version": "dev-master",
"name": "nodge/lessphp",
"source": {
"url": "https://github.com/Nodge/lessphp.git",
"type": "git",
"reference": "master"
},
"autoload": {
"classmap": ["lessc.inc.php"]
},
"dist": {
"url": "https://github.com/Nodge/lessphp/archive/master.zip",
"type": "zip"
}
}
}
],
"require": {
"nodge/lessphp": "*"
}
}
The accepted answer and clarifying answers all worked well for me when I had ex. an application, which needed a dependency I had forked and modified. I’d still use the accepted answer in this case.
However, when I had a package I wanted to distribute myself on Packagist, which also contained a forked and modified dependency, this approach no longer worked.
If someone were to try and install with this config, they’ll still get that same -> no matching package found. error message.
This answer and the linked Composer docs suggest that the repo settings have to be at the top-level composer.json. That means, someone installing this package would have to add that config to their composer.json file too—which adds a lot of unnecessary confusion to the install process.
Instead, I published my fork to Packagist. My understanding is that while forks are frowned upon, this would be considered a maintained fork, since I am using it for this new package.
Hopefully that’s helpful for anyone who has this problem with a package or library they’d like to distribute.