Skip to content

Strange naming convention if applying rules with root project #339

@StefMa

Description

@StefMa

Hi 👋 ,

I’m using the plugin with a setup roughly like this:

moduleGraphAssert {
    allowed = arrayOf(
        ":lib:.* -> :libraries",
        ":lib:.* -> :libraries-testing",
        ":lib:.* -> :lib:.*",
        ":feature:.* -> :libraries",
        ":feature:.* -> :libraries-testing",
        ":feature:.* -> :lib:.*",
        ":libraries-testing -> :.*",

        // Expected this to work for the root project:
        ": -> :.*",
    )

    restricted = arrayOf(
        ":lib:.* -X> :feature:.*",
        ":feature:.* -X> :feature:.*",
    )
}

The root project has dependencies on feature/lib modules.
I expected the root project to be matched as :, but the assertion failed with entries like:

'root  library' -> ':lib:authorization'
'root  library' -> ':feature:onboarding'

(note the two empty spaces here between root and library.

So I had to use this instead:

"root  library -> :.*"

The double space seems to come from moduleDisplayName():

fun Project.moduleDisplayName(): String {
  return displayName.replace("project", "")
    .replace("'", "")
    .trim()
}

For a root project display name like root project '[name]' instead of project ':[name]'.
So the root results in root [name].

Questioning the displayName here at all, because basically you want to use Project.path, no? 🤔
Anyways, another solution would be to check if its the root project (this.name == project.rootProject.name or so 🤷 ) and then return maybe just root or even :...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions