I'm currently learning gradle by reading a bunch of gradle books and looking at gradle build scripts for large Java projects like spring, hibernate and gradle frameworks in order to understand best practices for using gradle.
I noticed that in the gradle multiproject assembly there are two settings.gradle and build.gradle my questions.
- Is
settings.gradle required to create multiple projects? can it be transferred to the build.gradle file? - In the several open source projects that I looked at, I noticed that
settings.gradle actually contains the code, not just the settings, see examples of code that I found in the various settings.gradle files. What code is supposed to be put in settings.gradle ? is there any best practice regarding what happens in settings.grdale vs. build.gradle to follow? Do open source related projects violate these best practice rules?
From spring settings.gradle security project, select only a few lines of code from https://github.com/spring-projects/spring-security/blob/master/settings.gradle
include modules modules.each {name -> def p = findProject(":${name}") p.name = "spring-security-${name}" p.buildFileName = "${name}.gradle" } include samples samples.each {name -> def p = findProject(":${name}") def fullName = name.replaceAll('/','') p.name = "spring-security-samples-${fullName}" p.projectDir = new File(settingsDir, "samples/${name}"); if(!p.buildFile.exists()) { def buildFile = fullName.replaceFirst("-xml","") p.buildFileName = "${buildFile}.gradle" } }
And from the gradle project itself, a small fragment from https://github.com/gradle/gradle/blob/master/settings.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() }
source share