Child projects with different names other than build.gradle


(Luis Trigueiros) #1

Hi, I haven seen in one of the webcast that it is possible to have the build file with a different name other that the default build.gradle in a multi build project. I would like to have a different name for the build file based on the project something like:

rootProject +

|

±- child1+

|

|

|

±child1.gradle

±-child2+

|

|

|

±child2.gradle

|

±build.gradle

±setting.gradle

I know that this configuration has to be done in the settings.gradle, but don’t know the exact syntax, can anyone point me the details.

Thank you, Oscar


(Peter Niederwieser) #2

Here is how Gradle’s own build deals with this:

rootProject.name = 'gradle'
rootProject.children.each {project ->
    String fileBaseName = project.name.replaceAll("\p{Upper}") { "-${it.toLowerCase()}" }
    String projectDirName = "subprojects/$fileBaseName"
    project.projectDir = new File(settingsDir, projectDirName)
    project.buildFileName = "${fileBaseName}.gradle"
    assert project.projectDir.isDirectory()
    assert project.buildFile.isFile()
}

(Luis Trigueiros) #3

Thank you for pointing me to this example, I understand now how is done. Kind regards, Oscar