Files
my-gradle-plugins/dependency-export

Overview

This plugin will add 2 new tasks to your gradle projects

The exportDependencies task

The exportDependencies task will simply create a .dot file that contains your project's dependency graph, this task does not depend on anything and will succeed even if you don't have Graphviz installed.

The renderDependencies task

This task will invoke the exportDependencies task and then call Graphviz to create an visual representation of your dependency graph. Since this task invokes Graphviz directly, having it installed and available in your PATH is a requirement.

Install the plugin

Checkout this project and in the root folder run

./gradlew publishToMavenLocal

to install it to your local machine's Maven repository.

Add the plugin to your project

Add this plugin to you project simply adding it to your projects build.gradle

plugins {
    id "net.woggioni.plugins.dependency-export" version "0.1"
}

or to your build.gradle.kts if you prefer the Gradle Kotlin DSL

plugins {
    id("net.woggioni.plugins.dependency-export") version "0.1"
}

You can also enable it globally on your machine, just create a ~/.gradle/init.gradle file with this content

initscript {
    repositories {
        mavenLocal()
    }
    dependencies {
        classpath "net.woggioni.plugins:dependency-export:0.1"
    }
}

allprojects {
    apply plugin: net.woggioni.plugins.DependencyExportPlugin
}

this means that the plugin will be automatically enabled for all your Gradle projects, note that it doesn't alter the build process in any way except for creating the renderDependency and exportDependencies tasks, so it's relatively safe to do so.

If you need more information, the sample folder contains a basic Gradle project using the plugin, using both Groovy and Kotlin DSL.

Configure the plugin

This is the default configuration for both tasks using Groovy DSL

exportDependencies {
    configurationName = 'default'
    outputFile = 'dependencies.dot'
}

renderDependencies {
    format = 'xlib'
    outputFile = 'renderedDependencies'
    graphvizExecutable = 'graphviz'
}

and using Kotlin DSL

tasks.named<net.woggioni.gradle.dependency.export.ExportDependencies>("exportDependencies") {
    configurationName.set("compileClasspath")
    outputFile.set(project.file("dependencies.dot"))
}

tasks.named<net.woggioni.gradle.dependency.export.RenderDependencies>("renderDependencies") {
    format.set("xlib")
    outputFile.set(project.file("renderedDependencies"))
    graphvizExecutable.set("graphviz")
}

any configuration parameter can be overridden in your build.gradle (or build.gradle.kts) file or using its correspondent Gradle's project properties. For example to override the output format of the renderDependencies task from the CLI:

gradle exportDependencies --configuration=compileClasspath renderDependencies --format=svg

Parameter description

Attributes of task net.woggioni.gradle.dependency.export.ExportDependencies

  • configurationName will select the Gradle's configuration (that word you put in the dependencies section of your build before groupId:artifactId:versionId tuple) that will be represented in the graph. It can also be specified from CLI using --configuration.
  • outputFile will specify the location of the generated .dot file (note that if a relative path is provided, it will be interpreted as relative to the project's build directory). It can also be specified from CLI using --output.

Attributes of task net.woggioni.gradle.dependency.export.RenderDependencies

  • format will specify the format of the file generated by Graphviz. The default output format is xlib which, on a linux machine with a GUI, will open a window with an interactive (with zoom and pan) view of your dependencies (this is a special format that will not output any file). Otherwise you can choose between any other output format supported by Graphviz, refer to its official documentation for more details. It can also be specified from CLI using --format.
  • outputFile will specify the location of the generated file (note that if a relative path is provided, it will be interpreted as relative to the project's build directory). It can also be specified from CLI using --output.
  • graphvizExecutable will set the executable that will be launched to invoke Graphviz so that, if you have it installed in an exotic location outside of your PATH or, for any reason, you renamed it in some way, you can configure it here.

And finally use it!

Just run

gradle exportDependencies

or

gradle renderDependencies

and enjoy the mess of your horrible dependency thornbush. Now ask yourself if you really need that neural network framework for your FizzBuzz project.