6

I have a project built with Gradle, which contains libraries which can be used freely outside the main project, like this:

Project structure

The folders with a square at the bottom right are project modules.

I want to opensource this project (I mainly use Git and GitHub for tasks like this), but I have no idea how to organize it. Should I create separate repositories for each library (and if so, how can I link them to the main repository?), or should I put it all in one repo (I guess that's bad practice)?

The main criteria is that when git clone repo_url is run, it should recreate project structure one-to-one, so it can still be built with ./gradlew build.

4

1 Answer 1

5

You can create separate Git repositories for each library, publish them, then use Git submodules to link them to the main repository.

git submodule add submodule1_url directory1
git submodule add submodule2_url directory2
git commit -m "add submodules"

Working with submodules is a little more complex. After cloning the repo, you need to clone the submodules as well:

git clone repo_url
cd repo
git submodule init
git submodule update
./gradlew build

And voilà - you have a project with independent submodules.


You might also want to look at gradle: Chapter 50. Dependency Management. I haven't read that myself, but handling the dependencies outside of the SCM is often preferred, and as gnat was saying, you should take a look at the different options and decide for yourself.

2
  • 1
    well, according to the structure of my project I'll end up having three git repositories in one repo. Will Git handle it?
    – asn007
    Jul 6, 2014 at 13:20
  • Oops, sorry, I haven't completely read the link you provided. Solved then. Spoiler for those, who don't want to read git documentation: git will handle this.
    – asn007
    Jul 6, 2014 at 13:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.