composer.json in main project
"require": {"namth/my-core": "1.7.1"},
"repositories": {
"namth-my-core": {
"type": "git",
"url": "my-core ssh"
}
},
my-core have 1 tag version: 1.7.1
which correctly go to my-core private repo, in my-core composer.json
"require": {"namth/my-something": "^1.7.0"},
"repositories": {
"namth-my-mysomething": {
"type": "git",
"url": "my-something ssh"
}
my-something have 1 tag version: 1.7.1
Problem was when I run "composer update", it return error like:
namth/my-core 1.7.1 requires namth/my-something ^1.7.0 -> no matching package found.
My private repository was stored in Atlatssian Stash.
Am I missing something? Thanks
repositories config is available only for root package - only your main project can add custom repositories. Repositories configured in dependencies will be ignored.
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
You need to add both repositories to composer.json of your project, to make it work:
"repositories": {
"namth-my-core": {
"type": "git",
"url": "my-core ssh"
},
"namth-my-mysomething": {
"type": "git",
"url": "my-something ssh"
}
},
Related
I've been a bit confused how Composer loads dependencies of a private repository project. I have found this link but I am not sure if this comment is referring to nested repositories or simply any dependency of a repository. To clarify my situation:
I have a private git repository that I am attempting to add as a dependency for a project.
The private git repository is also a composer project, which contains a composer.json which requires publicly available packages.
I have the following code in my composer.json for the project.
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"version": "{arbitrary-version}",
"type": "package",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
"require": {
"{vendor}/{package-name}": "^0.0.1"
}
So if I were to do composer update on the project after these changes it will successfully download my package from the private repository, but it does not trigger a check/update on the composer.json of the private repository - so no vendor folder is created and critical dependencies are not installed. The private repository composer.json is below:
{
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
}
So my question is, is what I want to do achievable with a private repository via composer and if so does anybody know where I am going wrong?
package type is for non-composer dependencies. If you use this type, Composer will not even look for composer.json file inside of defined package source, you need to include all required information about package inside of the package declaration in your project composer.json:
"repositories": [
{
"type": "package",
"package": {
"name": "{vendor}/{package-name}",
"description": "{removed}",
"type": "library",
"require": {
"illuminate/database": "^5.6",
"chumper/zipper": "1.0.x",
"symfony/debug": "^4.0",
"vlucas/phpdotenv": "^2.4"
},
"version": "{arbitrary-version}",
"source": {
"url": "git#github.com:{github-username}/{github-repository}.git",
"type": "git",
}
}
}
]
But in your case (you have a package with proper composer.json) you should use vcs type:
"repositories": [
{
"type": "git",
"url": "git#github.com:{github-username}/{github-repository}.git"
}
]
I have two private repositories, let's call them RepoA and RepoB. RepoA is required by the RepoB and they are both private repos on gitlab with the port 620.
Here are the composer.json in both repo:
Repo A
{
"name": "namespace/repoA",
"description": "My repository A.",
"require": {
"php": ">=5.4"
}
}
Repo B
{
"name": "namespace/repoB",
"description": "My repository B.",
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
}
],
"require": {
"namespace/repoA": "dev-master"
}
}
Now let's say I have a project (ProjectA), which I want to install RepoB.
Project A
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master"
}
}
However, when I run my composer install, I get the following error:
Problem 1
- Installation request for namespace/repoB dev-master -> satisfiable by namespace/repoB[dev-master].
- namespace/repoB dev-master requires namespace/repoA dev-master -> no matching package found.
I understand that it's unable to find the package since it's a private repository, but since it's inside the repositories of the repoB, why is it not fetching it?
I thought it would work if I added the repositories to the Project A:
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
},
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master"
}
}
But it still does not work until I add it into my require of my Project Aas well:
{
"repositories": [
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoA.git"
},
{
"type": "vcs",
"url": "ssh://git#git.domain.com:620/namespace/repoB.git"
}
],
"require": {
"namespace/repoB": "dev-master",
"namespace/repoA": "dev-master"
}
}
Now my question is... How can I make composer install my repoA by specifying only my repoB?
You cannot and here is an explanation: Why can't Composer load repositories recursively?
I've got some packages host on the Gitlab of my company. I want to request a specific version of these packages but each time I try, composer download the latest commit of the master branch.
composer.json :
{
"name" : "MyProject",
"require" : {
"user/project" : "v0.5.0"
},
"type" : "project",
"repositories" : [
{
"url" : "git#gitlab.XXXX.fr:user/project.git",
"type" : "vcs"
}
],
"config" : {
"vendor-dir" : "private/class"
}
}
The structure of the repository of my package :
tag v0.5.0 : commit dd6ed3c8...
commit X,Y,Z
tag v0.7.0 : commit 15293ac6...
last commit f15600a1...
When I execute "composer install" :
Loading composer repositories with package information
Installing dependencies (including require-dev)
Analyzed 69 packages to resolve dependencies
Analyzed 67 rules to resolve dependencies
Installing user/project (dev-master f15600a)
Cloning f15600a1
It downloads the last commit only.
How can I configure the composer.json file of my project to use a specific tag ?
How to require a specific Git tag?
Change the version requirement to dev-master, followed by a hash # and the Git tag name, e.g. v0.5.0, like so:
"require": {
"vendor/package": "dev-master#v0.5.0"
}
How to require a specific Git commit?
Change the version requirement to dev-master, followed by a hash # and the Git commit reference, e.g. dd6ed3c8, like so:
"require": {
"vendor/package": "dev-master#dd6ed3c8"
}
Referencing: https://getcomposer.org/doc/04-schema.md#package-links
Define your own package and set version and reference
An alternative to working with repositories of "type": "vcs" is to define a custom package "type": "package" inside repositories and work with a reference.
The reference is either a Git commit hash, or a tag or branch name, like origin/master.
This will tie the version to a specific commit reference, in this case dd6ed3c8.
"repositories": [
# ...
{
"type": "package",
"package": {
"name": "vendor/package",
"version": "v0.5.0",
"source": {
"url": "git#gitlab.server.com:vendor/project.git",
"type": "git",
"reference": "dd6ed3c8"
}
}
}
]
Pull by git tag:
{
"repositories": [
{
"type": "git",
"url": "https://gitlab.xxx.com/some/repo.git"
}
],
"require": {
"some/repo": "1.0.2"
}
}
Pull by latest git commit:
{
"repositories": [
{
"type": "git",
"url": "https://gitlab.xxx.com/some/repo.git"
}
],
"require": {
"some/repo": "dev-master"
}
}
Pull by specific git commit:
{
"repositories": [
{
"type": "git",
"url": "https://gitlab.xxx.com/some/repo.git"
}
],
"require": {
"some/repo": "dev-master#68696f39"
}
}
Add repository via Composer Cli and pull latest git commit:
composer config repositories.repo git https://gitlab.xxx.com/some/repo.git
composer require "some/repo:dev-master"
composer update
To require a specific branch you can also just dev-branchname like this:
"require": {
"user/project" : "dev-my-branch"
},
You can use a specific version hash after '#', for example:
require": {
"user/project": "dev-master#31454f258f10329ae7c48763eb898a75c39e0a9f"
}
see: https://getcomposer.org/doc/04-schema.md#package-links
I've successfully set up Satis on my own server and am able to pull in packages from it.
However, dependencies that are required in those private packages are constantly being cloned at their bleeding edge version instead of the specified version constraint. I think that Satis is creating a local mirror of the latest dev-version. However I do not want to have a local mirror, I just need them to install directly from Packagist.
So how do I need to setup the project / package / Satis to have the dependencies in those private packages installed from Packagist?
Thanks.
This is my Satis build file:
{
"name": "Package Server",
"homepage": "http://packages.URL",
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:USERNAME/REPO.git",
"options": {
"ssh2": {
"username": "USERNAME",
"pubkey_file": "PUBFILE",
"privkey_file": "PRIVATEFILE"
}
}
}
],
"require-all": true
}
And this is the composer.json file of the project requiring the private package (package has no tagged releases):
{
"name": "Test Project",
"description": "",
"require": {
"php": ">=5.4.0",
"USERNAME/REPO": "*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.URL"
}
],
"minimum-stability": "dev"
}
And this is the private package's composer.json:
{
"name": "USERNAME/RPO",
"description": "",
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.0.*",
"vinkla/hashids": "~1.0"
},
"minimum-stability": "dev"
}
In your Satis config you defined "require-all": true.
This is default and selects all versions of all packages in the repository you defined.
You could try to remove "require-all": true in favor of a require section.
This means that Satis will only contain these specific packages and their versions, like so:
"require": {
"company/packageA": "*",
"company/packageB": "1.2.3",
"company/packageC": "2.0.0"
}
It's package cherry picking on Satis
So if I understand correctly I need to add the private packages that are available in the specified private repository in the require key and their own dependencies will then install from Packagist?
Add require-dependencies - this tells Satis to mirror not only the packages specified in the "require" section, but also all their dependencies.
See https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md#resolving-dependencies
Is it possible to have multiple packages resided in one defined repository or does every single package need their own repository url entry in Satis?
I think it's not possible to have multiple packages in one "type": "vcs" repository.
With "type": "composer" and a cloned packagist you can store multiple repos.
Think of http://drupal-composer.org with http://packagist.drupal-composer.org/.
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/somewhere/packageA" },
{ "type": "composer", "url": "https://packagist.org" }
],
"require": {
"package/packageA": "somewhere-dev",
"phpunit/phpunit": "*"
},
"require-dependencies": true
}
I created a package for Laravel 4 that worked properly when used in development in workbench but when I install it with Composer it keeps returning me the error Class 'Myvendor\Mypackage\MypackageServiceProvider' not found.
There is a particularity with my package which is that the name of my classes sources are different from the name of my package. Usually they are the same.
vendor/
Houle/
laravel-dynamite/
src/
Fhoule/
Dynamite/
DynamiteServiceProvider.php
I know that it can work because Laravel work's this way too.
vendor/
laravel/
framework/
src/
Illuminate/
And the property PSR-0 of my package composer.json seems to be properly configured:
"name": "Houle/laravel-dynamite",
...
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"classmap": [
"src/migrations",
"src/controllers",
"src/models"
],
"psr-0": {
"Fhoule\\Dynamite": "src/"
}
},
...
How I created my package:
Created the package with Artisan.
Maked it work properly in workbench directory
Pushed to private Bitbucket repo
Installed new instance of Laravel
Changed composer.json configuration to install my package (from private repository)
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"Houle/laravel-dynamite": "2.0.1"
},
"repositories": [{
"type": "package",
"package": {
"name": "Houle/laravel-dynamite",
"version": "2.0.1",
"source": {
"url": "git#bitbucket.org:Houle/laravel-dynamite.git",
"type": "git",
"reference": "v2.0.1"
}
}
}],
...
Added my package Service Provider to app/config/app.php:
'providers' => array(
'Fhoule\Dynamite\DynamiteServiceProvider',
)
That's where my application return the error Class 'Fhoule\Dynamite\DynamiteServiceProvider' not found.
What could be my issue?
I found my problem, it hadn't nothing to do with the way I named my vendor, package and classes.
It was that in my composer.json (root of the project), I set my repository type to package but like the Composer documentation states the type package is for packages that don't support Composer. That's why Composer wasn't updating my autoload_classmap.php file.
So if you want to use a private repository (like at Bitbucket or GitHub) you need to set the type of the repository to git:
{
"name": "laravel/laravel",
...
"require": {
"laravel/framework": "4.0.*",
"houle/laravel-dynamite": "dev-master"
},
"repositories": [{
"type": "git",
"url": "git#bitbucket.org:Houle/laravel-dynamite.git"
}],
...
}
Hope it helps someone.
The composer.json in your package (Package found in BitBucket) needs to specify the PSR-0 Autoloading component, rather than the composer.json file in your top-level Laravel project.
Can you show us the composer.json file for your repo in the private repository?