• Stars
    star
    337
  • Rank 125,272 (Top 3 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Gradle Plugin for visualizing your project's structure, powered by mermaidjs

Pre Merge Checks License Language

Introducing the Gradle Module Graph Plugin! 🌟

This plugin generates a Mermaid graph for your Gradle project, providing a visual representation of your project's module relationships. By illustrating how the parts of the project are connected, it makes it easier to understand the design and how they depend on each other.

A diagram about the current system is only useful if it's generated. If it is produced by hand it documents the author's belief, not the system. Still, important, but not an input for decision making. Development is primarily decision making. Enable it through custom tools. source

You can read more about the background story of this plugin here.

Features

  • Generates a Mermaid dependency graph of the modules in your Gradle project.
  • Automatically append the generated graph to your project's README file.
  • The raw code block automatically renders as a graph on both Github and Gitlab.

Getting Started

You'll just need to add it to your project's root build.gradle or build.gradle.kts file.

build.gradle (Groovy DSL)

Using the plugins DSL

plugins {
    id "dev.iurysouza.modulegraph" version "0.5.0"
}
Using Legacy Plugin application
    buildscript {
        repositories {
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
        dependencies {
            classpath "dev.iurysouza:modulegraph:0.5.0"
        }
    }

    apply plugin: "dev.iurysouza.modulegraph"

Configuring the plugin

  moduleGraphConfig {
    readmePath = "./README.md"
    heading = '### Dependency Diagram'
    showFullPath = false // optional
    orientation = dev.iurysouza.modulegraph.Orientation.LEFT_TO_RIGHT // optional
    linkText = dev.iurysouza.modulegraph.LinkText.NONE // optional
    theme = new dev.iurysouza.modulegraph.Theme.NEUTRAL() // optional
    // or you can fully customize it by using the BASE theme:
//   theme = new dev.iurysouza.modulegraph.Theme.BASE(
//        [
//            "primaryTextColor": "#fff",
//            "primaryColor": "#5a4f7c",
//            "primaryBorderColor": "#5a4f7c",
//            "lineColor": "#f5a623",
//            "tertiaryColor": "#40375c",
//            "fontSize": "11px"
//        ]
//    )
}

build.gradle.kts (Kotlin DSL)

Using the plugins DSL

plugins {
    id("dev.iurysouza.modulegraph") version "0.5.0"
}
Using Legacy Plugin application
    buildscript {
        repositories {
            maven {
                url = uri("https://plugins.gradle.org/m2/")
            }
        }
        dependencies {
            classpath("dev.iurysouza:modulegraph:0.5.0")
        }
    }

apply(plugin = "dev.iurysouza:modulegraph")

Configuring the plugin

moduleGraphConfig {
    readmePath.set("./README.md")
    heading.set("### Dependency Diagram")
    showFullPath.set(false) // optional
    orientation.set(Orientation.LEFT_TO_RIGHT) //optional
    linkText.set(LinkText.NONE) // optional
    theme.set(Theme.NEUTRAL) // optional
    // or you can fully customize it by using the BASE theme:
    // theme.set(Theme.BASE(
    //      mapOf(
    //          "primaryTextColor" to "#fff",
    //          "primaryColor" to "#5a4f7c",
    //          "primaryBorderColor" to "#5a4f7c",
    //          "lineColor" to "#f5a623",
    //          "tertiaryColor" to "#40375c",
    //          "fontSize" to "11px"
    //      )
    //   )
    // )
}

Configuration

To configure the Gradle Module Dependency Graph Plugin, you can set the following options:

  • readmePath: The path of the file where the dependency graph will be appended.
  • heading: The heading where the dependency graph will be appended.

Optional settings:

  • showFullPath: Whether to show the full path of the modules in the graph. Default is false. Use this if you have modules with the same name in different paths. This will remove the subgraphs from the graph.
  • theme: The mermaid theme to be used for styling the graph. Default is NEUTRAL.
    • Further customization is possible by setting the themeVariables property on the BASE theme. Check the mermaid docs for more info.
  • orientation: The orientation that the flowchart will have. Default is LEFT_TO_RIGHT.
  • linkText: Whether to add information as text on links in graph. Available values:
    • NONE: No text added. (Default.)
    • CONFIGURATION: The name of the configuration which the dependency belongs to (e.g. " implementation", "compileOnly", "jsMain").

Usage

Make sure you have a heading in your README with the same format as the one you set in the configuration, if not, the plugin will append it with the graph to the end of the file.

After that, just run the following command:

./gradlew createModuleGraph

Now, just look for the generated graph in your project's README file.

Example Diagram

You can expect the plugin to generate this kind of diagram after running the plugin:

%%{
  init: {
    'theme': 'neutral'
  }
}%%

graph LR
  subgraph app
    main
    playground
  end
  subgraph core
    common
    design-system
    footballdata
    reddit
  end
  subgraph features
    match-day
    match-thread
  end
  footballdata --> common
  match-day --> common
  match-day --> footballdata
  match-day --> design-system
  match-day --> reddit
  match-thread --> common
  match-thread --> footballdata
  match-thread --> design-system
  match-thread --> reddit
  playground --> match-thread
  playground --> match-day
  playground --> design-system
  reddit --> common
  main --> match-thread
  main --> match-day
  main --> design-system
  main --> common

Contributing 🀝

Feel free to open an issue or submit a pull request for any bugs/improvements.

License πŸ“„

This project is licensed under the MIT License - see the License file for details.

Buy Me a Coffee

If you found this project useful or want to support the development, consider buying me a coffee! Any donations are greatly appreciated and help to support the development. Relevant xkcd.

Buy Me A Pingado