简体   繁体   中英

Including subprojects using a wildcard in a Gradle settings file

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?

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 a project 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
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM