Question

In Gradle you need to define subprojects to be built in a 'settings.gradle' file. To build three child projects, you would do something like this:

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

The problem I'm having is that I have quite a few projects to include. Is there a way to use a wildcard in this definition? I'm looking for something like this:

include "*"

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

Was it helpful?

Solution

Can you do something like:

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

To include "Child1" up to "Child10"?

Obviously, you'd need to change the collect to some sort of folder scan, but it that quick test works then the scan has a good chance

OTHER TIPS

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])

Did the trick for me

The following code supports hierarchical of arbitrary depth:

rootDir.eachFileRecurse { f ->
    if ( f.name == "build.gradle" ) {
        String relativePath = f.parentFile.absolutePath - rootDir.absolutePath
        String projectName = relativePath.replaceAll("[\\\\\\/]", ":")
        include projectName
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top