AlexKorovyansky / gradle-dependency-graph-generator-plugin

Gradle plugin that generates dependency graphs from your project.

Home Page:http://vanniktech.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gradle-dependency-graph-generator-plugin

Build Status Codecov License

Gradle plugin that lets you visualize your dependencies in a graph.

Set up

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath "com.vanniktech:gradle-dependency-graph-generator-plugin:0.1.0"
  }
}

apply plugin: "com.vanniktech.dependency.graph.generator"

Note that this plugin can be applied at the root of the project or at a specific project. Both cases will just work.

This plugin is using the dot command line tool for generating the graphs hence you need to install it. Mac users can use brew install graphviz. Ubuntu users can sudo apt-get install graphviz.

Information: This plugin is also available on Gradle plugins

Snapshot

buildscript {
  repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
  dependencies {
    classpath "com.vanniktech:gradle-dependency-graph-generator-plugin:0.2.0-SNAPSHOT"
  }
}

apply plugin: "com.vanniktech.dependency.graph.generator"

Usage

By default this plugin will generate a generateDependencyGraph task that can be used to generate a dependency graph that could look like this. This graph was generated from my chess clock app.

Example graph.

There are extension points to be able to generate graphs which only include some dependencies and their transitive ones. The trick is to hook a Generator in over the dependencyGraphGenerator extension. Note that this is extremely experimental and will likely change between releases. It's still fun though.

Generator Example

We only want to show which Firebase libraries we're using and give them the typical Firebase orange.

import com.vanniktech.dependency.graph.generator.DependencyGraphGeneratorPlugin
import com.vanniktech.dependency.graph.generator.DependencyGraphGeneratorExtension.Generator
import com.vanniktech.dependency.graph.generator.dot.GraphFormattingOptions
import com.vanniktech.dependency.graph.generator.dot.Color
import com.vanniktech.dependency.graph.generator.dot.Shape
import com.vanniktech.dependency.graph.generator.dot.Style

plugins.apply(DependencyGraphGeneratorPlugin)

def firebaseGenerator = new Generator(
  "firebaseLibraries", // Suffix for our Gradle task.
  "", // Root suffix that we don't want in this case.
  { dependency -> dependency.getModuleGroup().startsWith("com.google.firebase") }, // Only want Firebase.
  { dependency -> true }, // Include transitive dependencies.
  { dependency -> new GraphFormattingOptions(Shape.BOX, Style.FILLED, Color.fromRgb(255, 203, 43)) }, // Give them some color.
)

dependencyGraphGenerator {
  generators = [ firebaseGenerator ]
}

This will generate a new task generateDependencyGraphFirebaseLibraries which when run will yield this graph:

Example Firebase graph.

Note that when using the dependencyGraphGenerator extension with custom generators you lose the default one, to add it back simply use the Generator.ALL instance:

dependencyGraphGenerator {
  generators = [ Generator.ALL, firebaseGenerator ]
}

License

Copyright (C) 2018 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0

About

Gradle plugin that generates dependency graphs from your project.

http://vanniktech.com

License:Apache License 2.0


Languages

Language:Kotlin 97.6%Language:Shell 2.4%