Search code examples
packageplantuml

How to generate UML package diagram with nested packages which may contain same names in different level?


I want to generate a package diagram with hierarchical packages which may contain duplicated names but not in the same level. e.g.:

@startuml
package A {
    package B {
        package C
    }
    package A
}
@enduml

I think, package A.A might be acceptable. But plantuml failed with this error: Thie element (A) is already defined.

I also try the following:

@startuml
folder A {
    folder B {
        folder C
    }
    folder A
}
@enduml

Then, plantuml failed with the same error.


Solution

  • You can draw diagrams with duplicated names if you include non-printing characters in the definition, e.g. by putting the name in quotes and including one or more space characters:

    @startuml
    package A {
        package B {
            package C
        }
        package "A "
        package "A  "
    }
    @enduml
    

    The additional spaces do not affect the layout in the diagram:

    UML class diagram with duplicated packages