Skip to content

kelvindev15/Kotlin2PlantUML

Repository files navigation

Kotlin2PlantUML

This library allows you to obtain a plantuml class diagram directly from your Kotlin (and Java) code base. You can either generate a simple class uml representation or the hierarchy of a root class.

javadoc CI

Usage

Command line


One way to generate a PlantUML class diagram is by executing the jar file. Arguments can be passed with the following structure:

java -jar kotlin2plantuml.jar fullyQualifiedClass [...options]

At least one argument must be passed. The first argument must be a fully qualified class name, otherwise an error will be thrown.

Note: The library uses the system ClassLoader to load classes thus only classes available in the run time classpath will be found. Running the library via jar may require that you also set it's classpath.


Options:


To understand which options can be passed you can run

java -jar kotlin2plantuml.jar --help

Here's the output of the help command:

usage: java -jar kotlin2plantuml.jar full.class.name [...options]
 -cp,--classpath <arg>           ':' separated paths (for classpath)
 -fv,--field-visibility <arg>    Max. field visibility (0=Public,
                                 1=Protected, 2=Internal, 3=Private)
 -h,--help                       Display this message
 -hf,--hide-fields               Hide fields on classes
 -hm,--hide-methods              Hide methods on classes
 -hr,--hide-relationships        Hide relationships between classes
 -mv,--method-visibility <arg>   Max. method visibility (0=Public,
                                 1=Protected, 2=Internal, 3=Private)
 -o,--output <arg>               Output file path
 -p,--packages <arg>             ':' separated packages (for subclasses)
 -r,--recurse                    Visit class class hierarchy

Based on the passed arguments a Configuration will be created to customize the output.

Example

java -jar kotlin2plantuml.jar my.fully.qualified.Class --packages look.here:and.also.here --recurse 

By default, the plantUml output file will be placed in build/reports/ named diagram.plantuml. You can change this by setting the output file with the --output option:

java -jar kotlin2plantuml.jar my.fully.qualified.Class --output ./path/to/file.plantuml 

Import into a Gradle project

Another possibility is to import the library into a gradle project. Just add this to your build file:

implementation("io.github.kelvindev15:Kotlin2PlantUML:<latest-version>")

and you're good to go. Now you can freely use the library API. Here's an example:

val myPlantUML = ClassDiagram(
    MyRootClass::class,
    configuration = Configuration(recurse = true)
).plantUml()

Reference