Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Scala2PlantUML

Build badge Maven-Central badge Scala Steward badge

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.

Example

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("```")

Example Class Diagram

sbt

Enable SemanticDB

For sbt versions >= 1.3.0:

semanticdbEnabled := true

For sbt versions < 1.3.0:

SemanticDB Version

addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "x.y.z" cross CrossVersion.full)
scalacOptions += "-Yrangepos"

Add Scala2PlantUMLPlugin

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@")

Generate the Diagram

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.

CLI

Install

Use Coursier to create a launcher for Scala2PlantUML:

cs install --channel https://git.io/Jqv1i scala2plantuml

Usage

scala2plantuml --help
println("```text")
nz.co.bottech.scala2plantuml.Scala2PlantUML.main(Array("--help"))
println("```")

Library

🚧 TODO: Document Library.

Limitations

  • 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.