I have a rather big project with lots of dependencies. The project is stored in a git repository and the dependencies are stored in dedicated git repositories linked as submodules. The dependencies can have further dependencies (again, using git submodules).
This works well. However, if two dependencies required both a third dependency I run into trouble on updates.
A dependency graph looks like this:
[Main Repo]
|
|-- [ModuleA]
| |
| \-- [ModuleC]
|
\-- [ModuleB]
|
\-- [ModuleC]
Right now I update the submodule pointer in ModuleA and ModuleB. This way both modules remain self contained. However, this is a lot of work.
How is this problem usually solved in bigger projects? I am looking for best practices to approach this kind of problem.
Thanks!
In these situations you can use git submodules to manually manage external dependencies. This guide discusses the pros/cons of dependency management with git submodules as well as some alternative approaches to consider to avoid the use of submodules.
You can use the following commands to use Git submodules in your repositories. Clone a repository and load submodules. To clone a repository containing submodules: $ git clone--recursive < URL to Git repo > If you have already cloned a repository and want to load its submodules: $ git submodule update --init. If there are nested submodules:
First choice: Use an appropriate build/dependency tool instead of git A dependency management tool is my current recommended way forward to handle the growing pains and the build times of sizeable projects. Keep your modules separated in individual repositories and manage their interdependency using a tool built for the job.
Git submodules. Git submodules are a feature of the Git SCM that allow you to include the contents of one repository within another by simply specifying the referenced repository location. This provides a mechanism of including an external library’s source into an application’s source tree.
In bigger project, what you want is keep all your dependencies on one level.
That doesn't mean that ModuleA
and ModuleB
don't keep their own dependency to ModuleC
.
That means your current main parent repo include a dependency on ModuleC
, which acts as the referent version for C
.
That also allows you to detect when a dependency has to be overridden as, in your case, for one of your two submodules: the dependency to ModuleC
for ModuleA
or ModuleB
will have to be overridden by the one to ModuleC
from your main Repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With