Expected Behavior Regardless of the buildFile names, no phantom subprojects should be created.
If a subproject has a default buildFile name like build.grade, the build setup should NOT create a phantom subproject.
Current Behavior If a new subproject is added in with structure like this spring-security-foo/spring-security-foo-bar, using a default buildFile name build.gradle under spring-security-foo-bar will result in the creation of a phantom subproject spring-security-foo.
No phantom subproject should be created due to the name change of the buildFile.
Context Settings.gradle should be updated to give a consistent behavior for different buildFile names. The issue is described here in gradle's documentation. https://docs.gradle.org/8.12/userguide/multi_project_builds.html. It will happen when creating a new sub-project if this settings.gradle file is used for both default buildFile name and custom buildFile name.
Code snippet to fix
buildFiles.each { File buildFile ->
boolean isDefaultName = 'build.gradle' == buildFile.name
if (isDefaultName) {
String buildFilePath = buildFile.parentFile.absolutePath
String projectName = buildFilePath.tokenize(File.separator)[-1]
configureProject(':' + projectName, projectName, buildFile)
} else {
String projectName = buildFile.name.replace('.gradle', '')
configureProject(':' + projectName, projectName, buildFile)
}
}
def configureProject(String projectPath, String projectName, File buildFile) {
include(projectPath)
def project = findProject(projectPath)
project.name = projectName
project.projectDir = buildFile.parentFile
project.buildFileName = buildFile.name
}
Comment From: sjohnr
Closing as a duplicate of gh-16322