How to group example projects together with Gradle

I've been writing PaperParcel for a few months now and it has a bunch of sample projects to demonstrate how to configure the library for different technologies. Having all of these samples in the root level got a bit overwhelming.

What I really wanted was to have an "examples" directory, and throw all the example projects in there. This is what many open-source libraries are already doing, e.g. okhttp has a "samples" directory. The issue is, I've only ever seen this done with maven projects, and PaperParcel is built with Gradle.

When you include a module in Gradle, it'll only look for that module in the root directory. The fix for this is to modify where Gradle looks for the project by changing the project's projectDir, e.g.:

In settings.gradle:

include ':kotlin-example'  
project(':kotlin-example').projectDir = new File("examples/kotlin-example")  

Now Gradle will be able to find the example project located under the "examples" directory.

Brad Campbell

Android application developer, currently working as the lead on the ANZ goMoney NZ applications. All of the opinions and code on this blog are my own, and not that of ANZ.