Git Product home page Git Product logo

dependency-graph-plugin's Introduction

dependency-graph-plugin

A simple Gradle plugin that shows the dependency graph of the project.

preview


Download maven-central

use 1.1.0 version!

plugins {
    id("land.sungbin.dependency.graph.plugin") version "$version"
}

Usage

  1. Download graphviz.
  2. Setting dependencyGraphConfig.
  3. Run ./gradlew dependencyGraph.
dependencyGraphConfig {
    /**
     * The path where the dot file of the graph will be generated.
     * The png of the graph is generated along this path, too.
     *
     * Default is "generated/dependency-graph/project.dot".
     */
    dotFilePath = "generated/dependency-graph/project.dot"

    /**
     * Whether to automatically delete the dot file after
     * the png is created from the dot file of the graph.
     *
     * Default is `true`.
     */
    autoDeleteDotFile = true

    /**
     * Name to be displayed at the top of the graph.
     *
     * Default is `null`.
     * `null` means: `${project.rootProject.name}`
     */
    projectName = null // String type 

    /**
     * The default **Hex** color to use when graphing uncolored dependencies.
     *
     * Defaults to `#eeeeee`, skipped graphing if `null` is provided.
     */
    defaultDependencyColor = "#eeeeee" // String? type

    /**
     * The format in which the graph image will be generated.
     *
     * Default is [OutputFormat.PNG].
     */
    outputFormat = OutputFormat.PNG // OutputFormat Type. Available: PNG, SVG, JPG

    /**
     * **[REQUIRE]** Add dependency information to the graph.
     *
     * @param builder The lambda that calculates the dependency information.
     *  - project: Instances of the Project to compute information
     *
     * @return A dependency information object. See [DependencyInfo].
     */
    fun dependencyBuilder(builder: (project: Project) -> DependencyInfo?)
}

/**
 * A dependency information object.
 *
 * @param color **Hex** color of the dependency
 * @param isBoxShape Whether that dependency will be displayed as a rectangle on the graph.
 * The default value is `false`, and in case of `false`, it is displayed as an oval.
 */
data class DependencyInfo(
    val color: String,
    val isBoxShape: Boolean = false,
)

Example

You can check sample project at here.

// example 1
dependencyGraphConfigs {
    dependencyBuilder { project ->
        with(project.plugins) {
            when {
                hasPlugin("project.three") -> DependencyInfo("#81d4fa", isBoxShape = true)
                hasPlugin("project.two") -> DependencyInfo("#ffc9ba")
                hasPlugin("project.one") -> DependencyInfo("#fcb96a")
                else -> null
            }
        }
    }
}

// example 2
dependencyGraphConfigs {
    dotFilePath = "assets/dependency-graph/project.dot"
    
    dependencyBuilder { project ->
        with(project) {
            when {
                plugins.hasPlugin(PluginEnum.AndroidApplication) -> DependencyInfo("#baffc9", isBoxShape = true)
                plugins.hasPlugin(PluginEnum.AndroidDfm) -> DependencyInfo("#c9baff")
                plugins.hasPlugin(PluginEnum.JavaLibrary) -> DependencyInfo("#ffc9ba")
                name.startsWith(UtilModulePrefix) -> DependencyInfo("#ffebba")
                name.startsWith(FeatureModulePrefix) && !name.contains(OnlyUiFeatureModulePrefix) -> DependencyInfo("#81d4fa")
                name.startsWith(UiFeatureModulePrefix) -> DependencyInfo("#00aeff")
                plugins.hasPlugin(PluginEnum.AndroidLibrary) -> DependencyInfo("#fcb96a")
                else -> null
            }
        }
    }
}

Credit

The original implementation is by JakeWharton.

License

This project is licensed under the MIT License. Please refer to the LICENSE file for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.