Skip to content

Gradle plugin to build PlantUML diagrams from code (for living and up-to-date documentation)

License

Notifications You must be signed in to change notification settings

RoRoche/plantuml-gradle-plugin

Repository files navigation

plantuml-gradle-plugin

Icon

Gradle plugin to build PlantUML diagrams from code (for living and up-to-date documentation).

Badges

Build

Build Status

Code coverage

codecov

Analysis

Codacy code quality Quality Gate Status Bugs Code Smells Duplicated Lines (%) Lines of Code Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

Dependencies

Known Vulnerabilities

License

GitHub

Version

Maven metadata URL

Activity

GitHub contributors GitHub last commit GitHub Release Date

Other

Elegant Objects
intellij-idea

DevOps By Rultor.com

Hits-of-Code

Dependency

Using the plugins DSL:

build.gradle
plugins {
    id "com.github.roroche.plantuml" version "{latest_version}" // (1)
}
  1. The plugin ID with the latest version.

build.gradle
buildscript {
    repositories {
        maven {
          url "https://plugins.gradle.org/m2/" // (1)
        }
    }
    dependencies {
        classpath "com.github.roroche:plantuml-gradle-plugin:{latest_version}" // (2)
    }
}

apply plugin: "com.github.roroche.plantuml" // (3)
  1. Declare the repository where to look for the plugin.

  2. Declare the dependency to the plugin.

  3. Apply the plugin.

Maybe you would have to configure the plugin management with repositories where to look for plugins:

settings.gradle
pluginManagement {
    repositories {
        gradlePluginPortal() // (1)
    }
}
  1. Include the official Gradle plugin portal.

Configuration

build.gradle
classDiagram { // (1)
    packageName = "com.github.roroche" // (2)
    outputFile = project.file('diagrams/class_diagram.plantuml') // (3)
    // outputFile = new File("${projectDir}/diagrams/class_diagram.plantuml") // (4)
    ignoredClasses = [ // (5)
            "com.github.roroche.plantuml.diagrams.Diagram\$Simple",
            "com.github.roroche.plantuml.diagrams.Diagram\$Wrap",
            "com.github.roroche.plantuml.classes.Classes\$Simple",
            "com.github.roroche.plantuml.classes.Classes\$Wrap"
    ]
}
  1. The name of the extension.

  2. The name of the package to scan.

  3. The file where to print the class diagram.

  4. Equivalent declaration to use explicit variable ${projectDir}.

  5. The classes to be ignored while building the class diagram (an array of strings).

Usage

Simply run the buildClassDiagram task, such as:

./gradlew buildClassDiagram

Output examples

link:diagrams/class_diagram.plantuml[role=include]
@startuml

class "BuildClassDiagramTask" {
  extension : ClassDiagramExtension
  metaClass : MetaClass
  execute()
  getProperty(String) : Object
  invokeMethod(String, Object) : Object
}

class "ClassDiagram"

class "ClassDiagramExtension" {
  packageName : String
  outputFile : File
  ignoredClasses : List<String>
  metaClass : MetaClass
  getProperty(String) : Object
  invokeMethod(String, Object) : Object
  setProperty(String, Object)
}

interface "Classes" {
  list() : List<Class<?>>
}

class "ClsFiltered" {
  ignored : Classes
  list() : List<Class<?>>
}

class "ClsInPackage" {
  packageName : String
  packageUrls : Collection<URL>
  reflections : Reflections
  list() : List<Class<?>>
}

class "ClsWithLog" {
  logger : Logger
  list() : List<Class<?>>
}

class "ClsWithNames" {
  names : List<String>
  list() : List<Class<?>>
}

interface "CustomTask" {
  execute()
}

interface "Diagram" {
  content() : String
  print(File)
}

class "DiagramWithLog" {
  logger : Logger
  print(File)
}

class "PlantUmlPlugin" {
  metaClass : MetaClass
  apply(Project)
  apply(Object)
  getProperty(String) : Object
  invokeMethod(String, Object) : Object
  setProperty(String, Object)
}

"BuildClassDiagramTask" --> "ClassDiagramExtension" : extension
"Classes" <-> "ClsFiltered" : /ignored
"Classes" <|-- "ClsInPackage"
"Classes" <|-- "ClsWithLog"
"Classes" <|-- "ClsWithNames"
"CustomTask" <|-- "BuildClassDiagramTask"
"Diagram" <|-- "ClassDiagram"
"Diagram" <|-- "DiagramWithLog"

@enduml
Class diagram

Opportunity

It’s possible to associate this plugin with this pretty good one: https://framagit.org/avaiss/plantuml-gradle-plugin

Here is the example of the configuration applied for this project:

build.gradle
plugins {
    id "org.fmiw.plantuml" version "0.1" // (1)
}

plantuml {
    options {
        outputDir = project.file('diagrams') // (2)
    }

    diagrams {
        classes {
            sourceFile = project.file('diagrams/class_diagram.plantuml') // (3)
        }
    }
}

generateDiagramClasses.dependsOn(buildClassDiagram) // (4)
  1. Declare the dependency.

  2. Configure the output directory where to store SVG files.

  3. Configure the source file to provide to the plugin.

  4. Force the buildClassDiagram task to be performed before executing the generateDiagramClasses one.

Icon credits

Icons made by Eucalyp from www.flaticon.com

About me

Twitter Follow
LinkiedIn