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.gradle3 settings.gradle4 bluewhale/5 build.gradle6 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.gradle3 settings.gradle4 bluewhale/5 bluewhale.gradle6 krill/7 krill.gradle
The answer is to turn to your settings.gradle
file.
1// settings.gradle2include "bluewhale", "krill"3rootProject.name = "water"4rootProject.children.each { child ->5 def moduleName = child.name6 child.name = "${rootProject.name}-${moduleName}"7 child.buildFileName = "${moduleName}.gradle"8}