Seven Story Rabbit Hole

Sometimes awesome things happen in deep rabbit holes. Or not.

   images

A Stubbed Out Gradle Multi-project Hierarchy Using Git Submodules

I’m about to split up the couchbase-lite android library into two parts: a pure-java and an android specific library. The android library will depend on the pure-java library.

Before going down this project refactoring rabbit hole for the real project, I decided to stub out a complete project hierarchy to validate that it was going to actually work. (I’m calling this project hierarchy “stubworld” for lack of a sillier name)

There are five projects in total, here are the two top-level projects

https://github.com/tleyden/stubworld-app-android (an Android app)

https://github.com/tleyden/stubworld-app-cmdline (a pure java Command Line application)

The projects are all self contained gradle projects and can be imported in either Android Studio or IntelliJ CE 13, and the dependencies on lower level projects are done via git submodules (and even git sub-submodules, gulp). In either top level project you can easily debug and edit the code in the lower level projects, since they use source level dependencies.

The biggest sticking point I ran into was that initially I tried to include a dependency via:

1
compile project(':libraries:stubworld-corelib-java')

which totally broke when trying to embed this project into another parent project. The fix was to change it to use a relative path by removing the leading colon:

1
compile project('libraries:stubworld-corelib-java')

I’m posting this in case it’s useful to anyone who needs to do something similar, or if any Gradle / Android Studio Jedi masters have any feedback like “why did you do X, when you just could have done Y?”

Comments