2

My Symfony2 (GregCMS) project contains several Bundle which can be used separately. I created a bare local repository (RepoGregCMS) which has been initiated with my project.

I really need to embed my bundle within a single Symfony project. Moreoever, I can not use github: repo must be kept out of the internet.

What I want to be able to do is to use my projet's bundle from any other project. Theses bundle have been made to setup new project with some features customer will pay for.

So I created a composer.json file within my GregCMS/src/GregCMS/CoreBundle as well as in GregCMS/src/GregCMS/WidgetsBundle.

Ex:

{
    "name" : "gregcms/corebundle",
    "description" : "Greg CMS core bundle",
    "type" : "symfony-bundle",
    "authors" : [{
        "name" : "Greg",
        "email" : "author@mail.com"
    }],
    "keywords" : [
        "cms core bundle"
    ],
    "license" : [
        "MIT"
    ],
    "require" : {
    },
    "autoload" : {
        "psr-0" : {
            "GregCMS\\CoreBundle" : ""
        }
    },
    "target-dir" : "GregCMS/CoreBundle",
    "repositories" : [{
    }],
    "extra" : {
        "branch-alias" : {
            "dev-master" : "1.0-dev"
        }
    }
}

Now, what I want to do is creating a new Symfony project which will require my CoreBundle.

I created the projet and then added the following line to require within its composer.json:

...
"gregcms/corebundle" : "dev-master"
...

I also added the repository path:

...
"repositories": [
    {
        "type": "git",
        "url": "../RepoGregCMS"
    }
],
...

Thus said, I try to install the new created dependency, but I finally got this error:

[Composer\Repository\InvalidRepositoryException]                                                 
No valid composer.json was found in any branch or tag of ../RepoAubergineCMS, could not load a   
  package from it.

I think the fact that my repository has been initiated as bare and thus does not contain the files or directories make composer going crazy.

I also tried to point on a my local branch of my repository (GregCMS) and got it almost working. I had the following error:

The requested package gregcms/corebundle could not be found in any version, there may be a typo in the package name

How could I make my Bundle available for other projects with composer ? Is this even a good practice to try pointing on a bare repository? I'd like to say that what I'm trying to do is the same thing that Sensio did with symfony: create several component in one single project/repo and being able to use them separately or all at once.

I'm kind of lost there. Thanks for help

EDIT:

I succeeded at creating a bare repository and use it as pointed CVS. But I still got the error about the not found package. I can't figure out why I face this error.Configuration files are the same as beyond. I miss something but can't figure out what.

Grégory Elhaimer
  • 2,731
  • 1
  • 16
  • 21

1 Answers1

0

Every package should have a proper composer.json at the root level. You have to create a composer.json for GregCMS if you want to have a package like "gregcms/gregcms" and every other package like "gregcms/corebundle" should have its composer.json too at the root of the repository not in a subdirectory like GregCMS/src/GregCMS/CoreBundle. Symfony also has one for the main package and one for every subpackage. Symfony (and some other projects) manages this a technique called "subtree split".

By the way take a look at https://about.gitlab.com/gitlab-com/ they offer unlimited privete repository hosting for free.

1ed
  • 3,668
  • 15
  • 25
  • This still can't work with bare repositories. My question was all about that, how do I manage to use composer with bare repository ? Is this even possible ? – Grégory Elhaimer Jul 02 '15 at 21:54
  • Yes, you can use bare repositories as well, as composer clones the repo, but you need to add proper composer.json files. But note that this way your projects won't be portable. – 1ed Jul 02 '15 at 23:09
  • What do you mean by "not portable" ? – Grégory Elhaimer Jul 02 '15 at 23:17
  • You won't be able to run composer install or update on other machines without the bare repository. – 1ed Jul 02 '15 at 23:21
  • What would prevent from it ? – Grégory Elhaimer Jul 02 '15 at 23:26
  • Well, you can run it actually :), but it will give you an error as it will not be able to read the package definitions from the composer.json file in the bare repository stored on another machine. But it's ok if the bare repository will be available by copying there or something. – 1ed Jul 02 '15 at 23:45
  • So it would be better to use a simple git init to create the repo then. Is there something special about using a simple got init ? Like am I obliged to pull modification manually from the clone I've made ? – Grégory Elhaimer Jul 02 '15 at 23:47