Scenario
I have a Plugin in PHP that I've written and want to keep it as a private repository. I want to set up the versioning in Git. I know there are tags for this, but don't know how the convention works for Composer.
Current composer.json for my package/plugin:
{
"name": "Test/Upload",
"description": "Useful functions for image uploading.",
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
}
}
Current composer.json for my project to include the above package/plugin:
{
"name": "multistepform",
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}
Currently I have no tags in the package/plugin.
Qs
1) Does Composer require tags in a repository in order for it to use it?
2) How should one tag their private repository for use with Composer?
3) How to include this package in a different project (using the above context)?
Just to add to #tigrang's comment and list out the explicit steps:
add your git repo using "repositories" in your composer.json
tag your package with a version number (I suggest using Semantic versioning, Keep A Changelog and my git plugin git-semver)
VERSION=0.1.0 && git tag ${VERSION} && git push origin ${VERSION}
add your package under require
you can also use "dev-master" in your require if you don't want to add version tags and want to get the latest changes to package when running composer update. This requires setting:
minimum-stability: dev
Final composer.json:
{
"name": "multistepform",
"repositories": [
{
"type": "git",
"url": "https://github.com/Test/Upload.git"
}
],
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*",
"Test/Upload": "0.1.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}
Related
I'm currently working on a Composer package and now I want to test how it would integrate in my current application without pushing it to a remote.
So I stumbled upon this blog post which explains how to do that. However, that didn't work. I'm getting the message
Your requirements could not be resolved to an installable set of packages.
Problem 1 - The requested package tzfrs/x-bundle could not be found in any version, there may be a typo in the package name.
My directory structure looks like this
dev
Project
composer.json
Package
composer.json
The composer.json of my package looks like this
{
"name": "tzfrs/x-bundle",
"license": "proprietary",
"require": {
"php": "^7.0",
"psr/log": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.5"
},
"autoload": {
"psr-4": { "tzfrs\\XBundle\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
}
}
And the one of my project looks like this (I'm leaving the symfony stuff and other packages/stuff out)
{
"repositories": [
{
"type": "git",
"url": "../Package",
}
],
"minimum-stability" : "beta",
"require": {
"tzfrs/x-bundle": "*"
}
}
So when doing composer update tzfrs/x-bundle I should get my new project right? However, I'm getting the message I posted above. What am I doing wrong here?
I already did git init in my package folder and also comitted all my changes. So I have a repo which is not empty already.
When I want to require my project, the following errors shows up:
The requested package mvc-php/framework could not be found in any version, there may be a typo in the package name.
The "mvc-php/framework" is a git folder.
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
Project i want to require:
{
"name": "mvc-php/framework",
"description": "PHP MVC framework",
"autoload": {
"psr-4": {
"Mvc\\" : "src/"
}
},
"require": {
"php": ">=7.0"
}
}
Instead of just the branch name, you must require branchName#dev
https://getcomposer.org/doc/articles/versions.md#branches
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master#dev"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
The requested package X/Y could not be found in any version.
The requested package needs to be a git folder with the committed and existing composer.json file. Then to reference specific branch, you need to add the dev- prefix, so dev-master, not master.
Example
Here is the minimal working example:
File: composer.json
{
"require": {
"local/my_package": "dev-master"
},
"repositories": [
{
"packagist.org": false
},
{
"type": "path",
"url": "my_package/"
}
]
}
File: my_package/composer.json
{
"name": "local/my_package",
"require-dev": {
"symfony/console": "*"
}
}
Note: Above file is under local Git repository. To create one, run: git init && git commit -am 'Files'.
Troubleshooting
To troubleshoot the issue, run:
composer install -vvv
Also consider running: composer diagnose to identify common Composer errors.
As this is the first response when searching the error text on Google, I will also put my fix here, despite not being 100% relevant to the OP.
When you are requiring the repo, you need to make sure that your requires statement matches the name of the project in the composer.json of the project.
So if the name had been "name": "mvc-php/app-framework", in the framework project, then the require would need to be:
"require": {
"mvc-php/app-framework": "dev-master"
},
This is more applicable when you are adding a git repo. Especially when forking, as sometimes the git url might be different from the composer.json name.
Additionally (and this is the part relevant to OP), you now need to do dev-branch_name instead of branch_name#dev when requiring. I don't know when this changed, or if the old method is unusable. But this is what the current composer docs now say.
If you want Composer to check out a branch instead of a tag, you need to point it to the branch using the special dev-* prefix
Composer Documentation - Versions and Constraints - Branches
Another Gotcha to be Aware Of:
I changed the name of a package I developed and was just testing a branch on it. I had followed all the correct naming conventions mentioned above but was still getting the given error.
It turns out that for the name change to be picked up, you have to update the package name in composer.json on the main branch of the package repo (Master for me) even if you are not using that branch within your project.
It is important to note that if you do not add your own mirror source to the global variable, an error will occur where the sub-scene is not found.
You can add this in composer.json:
"repositories":[
{
"type":"composer",
"url":"https://packag"
}
],
when I want to install some library by composer, it's enough to write:
composer require vendor/library
and composer downloads it from github. It's not necessary to give url for every "vendor/library" to composer.json. Composer does it "internally". But when I'd like to add some library from e.g. bitbucket, I have to create this composer.json:
{
"require": {
"vendor/my-private-repo1": "dev-master",
"vendor/my-private-repo2": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo1.git"
},
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo2.git"
}
]
}
I have to specify an url of every library I want to install, even if they are from the same project. Is there any way to make it shorter? Can I do something like this:
{
"require": {
"vendor/my-private-repo1": "dev-master",
"vendor/my-private-repo2": "dev-master",
"vendor/my-private-repo3": "dev-master",
"vendor/my-private-repo4": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/*"
}
]
}
I hope my question is understandable. Thank you.
You either need to specify each repository separately, or manage your composer packages with satis or toran proxy. You'll still need to define your repositories, but only once (in satis or toran).
I have a project that has a dependency to 'webiny/crypt' package (I'm the owner of webiny/crypt repo also https://github.com/Webiny/Crypt).
{
"require": {
"webiny/crypt": "dev-master"
},
"minimum-stability": "dev"
}
Inside composer.json in webiny/crypt repo, I need to define a dependency to this repo: https://github.com/ircmaxell/php-cryptlib
That repo is not available on packagist, but inside its github repo it has a composer.json file.
I tried several solutions, but none of them worked. Here are some examples of what I tried...this is the content of composer.json of webiny/crypt.
Example 1:
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ircmaxell/PHP-CryptLib"
}
],
"require": {
"php": ">=5.4.0",
"webiny/class-loader": "dev-master",
"webiny/config": "dev-master",
"webiny/std-lib": "dev-master",
"ircmaxell/PHP-CryptLib": "*"
}
Example 2:
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ircmaxell/PHP-CryptLib"
}
],
"require": {
"php": ">=5.4.0",
"webiny/class-loader": "dev-master",
"webiny/config": "dev-master",
"webiny/std-lib": "dev-master",
"CryptLib/CryptLib": "*"
}
Also I tried both examples with 'dev-master' version instead of '*' on the CryptLib repo.
From the composer docs # https://getcomposer.org/doc/05-repositories.md#repository
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.
I think your only option, unless you want to tell your users to add that repo too, is to fork https://github.com/ircmaxell/PHP-CryptLib and then publish it to packagist. Maybe drop the author an email regarding this first tho.
Sorry, probably not the answer you were looking for.
I'm try using CakePHP for the first time with composer, but I have some problems.
I have this composer.json:
{
"name": "example.com.br",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"config": {
"vendor-dir": "Vendor/"
},
"require": {
"php": ">=5.4",
"pear-cakephp/cakephp": ">=2.4.3",
"cakephp/debug_kit": "2.2.*",
"smottt/wideimage": "dev-master"
},
"extra": {
"installer-paths": {
"app/Plugin/DebugKit": ["cakephp/debug_kit"],
"app/Vendor/Wideimage": ["smottt/wideimage"]
}
}
}
When I run composer install (or update) --prefer-dist, everything works except smottt/wideimage.
This package is being installed in the /Vendor folder instead /app/Vendor, so, installer-paths was ignored.
Of course, what Danack has said is true: the composer-installers plugin only supports a select list of package types.
In response to that, I have written an extension for the composer-installers plugin which allows any arbitrary package type to be handled by the "installer-paths" directive.
Simply require oomphinc/composer-installers-extender in your composer.json and add support for any additional arbitrary package types:
"extra": {
"installer-types": ["library"],
"installer-paths": {
"special/package/": ["my/package"],
"path/to/libraries/{$name}/": ["type:library"]
}
}
For packages that don't specify a type, use the default type library.
From the documentation.
You cannot use this to change the path of any package. This is only
applicable to packages that require composer/installers and use a
custom type that it handles.
From one of the packages you're installing:
{
"name": "smottt/wideimage",
"description": "An open-source PHP library for image manipulation. (With namespaces, PHP 5.3+)",
"homepage": "http://wideimage.sourceforge.net",
"type": "library",
"license": ["GPL-2.0","LGPL-2.1"],
"version": "11.02.19",
"autoload": {
"psr-0" : {
"WideImage" : "lib/"
}
}
}
So basically the package you're trying to install doesn't support custom install paths.
Use option "script" of composer (work only with linux) :
"scripts": {
"post-install-cmd": [
"php -r \"system('mv '.getcwd().'/Vendor/smottt/wideimage '.getcwd().'/Vendor/Wideimage');\""
]
}
Add your custom types to the installer-types:
{
"installer-types": ["library", "myttype-1", "mytype-2"]
}
https://packagist.org/packages/oomphinc/composer-installers-extender