piotrek
piotrek

Reputation: 14550

how to include all subdirectories as gradle modules?

I'm going to have a lot of submodules in my main project directory x, like x/module1, x/module2...

can i avoid manually adding every single module into settings.gradle? can i somehow script it to find all the subdirectories and add them automatically?

Upvotes: 3

Views: 3305

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14533

As cricket_007 already mentioned, Gradle is based on the Groovy programming language (which is, like Java, executed in the JVM) and the settings.gradle file is nothing more but a Groovy script.

Whenever you use include 'project', the include method of a Settings instance is called, so for your goal, you could simply create a loop which iterates over all folders and calls include for each of them.

A more 'groovyesque' approach would be the usage of a closure for each subdirectory, provided by the Groovy SDK extension for the File class:

file('.').eachDir { sub ->
    include sub.name
}

There are multiple ways to solve your problem, e.g. since the include method accepts an array of project path strings, you could also aggregate all required paths first and pass them all together. Simply get familiar with the Gradle docs and decide on your own, what solution suits your case the best.

Upvotes: 4

Related Questions