Scala2PlantUML generates PlantUML diagrams from Scala code.
It comes as a standalone library, a CLI tool and an sbt plugin.
Scala2PlantUML consumes SemanticDB files so you will need to know how to create those or simply follow the sbt setup instructions below.
scala2plantuml \
--url 'https://repo1.maven.org/maven2/nz/co/bottech/scala2plantuml-example_@SCALA_VERSION@/@VERSION@/scala2plantuml-example_@SCALA_VERSION@-@VERSION@.jar'\
--project example \
"nz/co/bottech/scala2plantuml/example/Main."
println("```text")
nz.co.bottech.scala2plantuml.Scala2PlantUML.main(Array("--project", "example", "nz/co/bottech/scala2plantuml/example/Main."))
println("```")
For sbt versions >= 1.3.0
:
semanticdbEnabled := true
For sbt versions < 1.3.0
:
addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "x.y.z" cross CrossVersion.full)
scalacOptions += "-Yrangepos"
For most use cases you should add Scala2PlantUML as a global plugin since your build is unlikely to depend on it.
Create ~/.sbt/1.0/plugins/scala2PlantUML.sbt
containing:
addSbtPlugin("nz.co.bottech" % "sbt-scala2plantuml" % "@VERSION@")
Run the scala2PlantUML
task from sbt:
scala2PlantUML "com/example/Foo#"
This accepts the following arguments:
--include
--exclude
--output
Refer to the CLI Usage for the definition of these arguments.
Use Coursier to create a launcher for Scala2PlantUML:
cs install --channel https://git.io/Jqv1i scala2plantuml
scala2plantuml --help
println("```text")
nz.co.bottech.scala2plantuml.Scala2PlantUML.main(Array("--help"))
println("```")
🚧 TODO: Document Library.
- Only class diagrams are supported.
- Only inheritance or aggregations are supported, compositions are shown as aggregations.
- Aggregations are shown between types not between fields. There is a [bug][namespaced field links] in PlantUML which prevents us from being able to do this reliably.
- There is no reliable way to determine the path to a SemanticDB file from any symbol.
If Scala2PlantUML is unable to find your symbols then the following may help:
- Only have a single top level type in each file.
- Ensure that the file name matches the type name.
- Nest any subclasses of a sealed class within the companion object of the sealed class.