John Tipper
Navigate back to the homepage

Gradle for large projects – customising multi-project build files

John Tipper
July 18th, 2018 · 1 min read

Gradle supports multi-project builds, in which each project, or module, located underneath a single directory, is a separate Gradle project. Here is an example of such a directory structure, taken from the documentation:

1water/
2 build.gradle
3 settings.gradle
4 bluewhale/
5 build.gradle
6 krill/
7 build.gradle

Note however, that each project has its own build.gradle. When you have many modules in your project and you have several of the build.gradle files open in your IDE, if they are similar then it can quickly become a nightmare trying to work out which one is which (you’ll generally have the titlebar showing part of a path and the filename, all of which look very similar). Wouldn’t it be good to have a different name for each module with a single build.gradle file at the top level to tie everything together? Something like the below, perhaps?

1water/
2 build.gradle
3 settings.gradle
4 bluewhale/
5 bluewhale.gradle
6 krill/
7 krill.gradle

The answer is to turn to your settings.gradle file.

1// settings.gradle
2include "bluewhale", "krill"
3rootProject.name = "water"
4rootProject.children.each { child ->
5 def moduleName = child.name
6 child.name = "${rootProject.name}-${moduleName}"
7 child.buildFileName = "${moduleName}.gradle"
8}

More articles from John Tipper

Gradle – Integration Testing for Gradle Plugin Development

How to get started with Integration Testing for Gradle plugin development.

July 18th, 2018 · 1 min read

How to connect multiple AWS accounts to Direct Connect using PrivateLink

Connect multiple AWS accounts to Direct Connect using PrivateLink

August 16th, 2021 · 6 min read
© 2018–2021 John Tipper
Link to $https://twitter.com/john_tipperLink to $https://github.com/john-tipperLink to $https://www.linkedin.com/in/john-tipper-5076395