문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top