Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] Settings.gradle's logic to handle different buildFile name could result in phantom subproject #16376

Closed
guesshe opened this issue Jan 8, 2025 · 1 comment
Assignees
Labels
in: build An issue in the build status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@guesshe
Copy link

guesshe commented Jan 8, 2025

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
}
@guesshe guesshe added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jan 8, 2025
@sjohnr
Copy link
Member

sjohnr commented Jan 8, 2025

Closing as a duplicate of gh-16322

@sjohnr sjohnr closed this as completed Jan 8, 2025
@sjohnr sjohnr self-assigned this Jan 8, 2025
@sjohnr sjohnr added status: duplicate A duplicate of another issue in: build An issue in the build and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: build An issue in the build status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants