Gradle multi project (module) example – Type II (flat)

In this series of posts, we will see various ways to implement multi module, hierarchical / parent-child projects using gradle. To provide a working example, this application implements a simple spring boot based rest like service.

This series:
Maven multi module example
Gradle multi project (module) example – Type I (nested)
Gradle multi project (module) example – Type II (flat)

The application contains 3 modules.

  • parent – parent gradle project
  • service – service module
  • web – web module

Though, the parent project can also contain src directory, in this example, src directory is not present and it just contains gradle files.

Directory structure


As you can see above, the root project directory ‘sample-gradle-hierarchical-flat-example’ contains 3 projects/directories which are ‘parent’, ‘service’ and ‘web’. Though this follows a flat structure physically, the ‘service’ and ‘web’ projects are child projects to ‘parent’ logically.

parent/settings.gradle = 'parent'
includeFlat 'service'
includeFlat 'web'

In terms of configurations, the only difference between nested vs flat structure lies in the settings.gradle file where we use includeFlat in case of flat structure and in nested structure, we use include.

Unlike the nested structure, the flat structure helps in terms of source control by providing the capability to create individual repository for each projects.

For more explanations and code, please refer to the first post in this series, Gradle multi module example – Type I (nested).

Build & Test

To build and execute, under parent directory, execute the following command.

gradle bootRun

To test, on browser, point to the following url.


Please refer to gradle documentation to explore more about multi module builds using gradle.

This entry was posted in java and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

2 Responses to Gradle multi project (module) example – Type II (flat)

  1. Gennady says:

    Thanks a lot, it’s very useful. The only thing I see that trying to build the subproject from its folder fails. As far as I understand that’s because the process fails to locate settings.gradle located in the parent folder. Do you know if that is something that can be fixed?


  2. Sri says:

    I had same issue as above comment, how can we run the build from inside child project (Service or Web), how do refer the build to parent build file when running from child project? is it possible?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s