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.

Posted in java | Tagged , , , , , , , , , , , , , , | 2 Comments