Introducing IncludeMe

Josh Burton
Trade Me Blog
Published in
2 min readMar 18, 2018

Working across multiple repositories, apps and libraries can be hard. Add in a large team and it can get really tricky!

How do you make changes to a library module and consume them from an app at the same time?

Publish to a local maven repository? Publish snapshots? Copy around binaries?

Fortunately Gradle comes with a little known feature called Composite Builds to solve this problem.

What are Composite Builds?

A composite build is simply a build that includes other builds. In many ways a composite build is similar to a Gradle multi-project build, except that instead of including single projects, complete builds are included.

In other words, composite builds allow an external project to be compiled as if it were a module in the current project.

Composite builds handle dependency substitution, and Android Studio/IntelliJ IDEA even pull in the sources for that project.

It’s pretty much magic 🙌.

A project (AnApp) with a library (MapMe) included as a Gradle Composite Build

What is IncludeMe?

So if composite builds are so great, what is IncludeMe all about?

Composite builds are usually configured via a projects settings.gradle like so:

//settings.gradleincludeBuild '../path/to/my/project'
includeBuild '../path/to/my/other/project'

The above approach has a few issues:

  • the developer needs to remember or lookup the path to other projects
  • the developer must remember not to commit the changes.

For a single developer this is not so hard, but we saw a way to make this better! So we built IncludeMe.

IncludeMe is a Gradle plugin that allows projects to be included as a composite build with a simple toggle.

IncludeMe creates an include.properties file in the project with simple toggles to include other projects.

#include.propertiesmyProject=false
myOtherProject=true

Set one of these properties to true, perform a Gradle sync and the project will be magically included in your build 🎉.

How does it work?

IncludeMe is really simple.

It scans the current project’s parent directory for other Gradle projects. Additional search paths can be declared as well.

Under the hood IncludeMe simply instructs Gradle to include a project as a composite build. It’s all very simple. Check out the source!

Try it out

Here at Trade Me we’ve found IncludeMe to be a handy tool when working on Android apps and libraries. We hope you do too!

Getting started is simple:

buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'nz.co.trademe.includeme:includeme:1.0.1'
}
}

include ':app'

apply plugin: 'nz.co.trademe.includeme'

If you liked this article make sure to 👏 it, and follow me on Twitter!

--

--

Josh Burton
Trade Me Blog

Freelance Android Developer. Fueled by coffee. @athornz on Twitter.