Including subprojects using the template in the Gradle settings file

In Gradle, you need to define the subprojects that will be created in the settings.gradle file. To create three child projects, you would do something like this:

include "child1", "child2", "child3"

The problem I am facing is that I have many projects to include. Is there a way to use a wildcard in this definition? I am looking for something like this:

include "*"

This, of course, does not work. It would be much easier to work with, as I have many subprojects to include. Is there a way to automatically include subdirectories as projects?

+3
source share
3 answers

- :

include (1..10).collect { "Child$it" }

"Child1" "Child10"?

, - , ,

+1

include rootDir.listFiles().findAll { 
     it.isDirectory() 
     && !( it =~ ".*/\\..*") // don't add directories starting with '.'
     && !( it =~ "^\\..*") // don't add directories starting with '.'
    }.collect { 
        it.getName() 
    }.toArray(new java.lang.String[0])

+4

The following code supports a hierarchy of arbitrary depth:

rootDir.eachFileRecurse { f ->
    if ( f.name == "build.gradle" ) {
        String relativePath = f.parentFile.absolutePath - rootDir.absolutePath
        String projectName = relativePath.replaceAll("[\\\\\\/]", ":")
        include projectName
    }
}
0
source

Source: https://habr.com/ru/post/1733534/


All Articles