Skip to content

Scabbard

A tool to visualize and understand your Dagger 2 dependency graph.
More advanced examples.

Features

  • Visualize entry points, dependency graph, component relationships and scopes in your Dagger 2 setup.

  • Minimal setup - Scabbard's Gradle plugin prepares your project for graph generation and provides ability to customize graph generation behavior.

  • IDE integration - Easily view a @Component or a @Subcomponnet graph directly from source code via gutter icons (IntelliJ/Android Studio).

  • Supports both Kotlin and Java.

What's new

Recent additions include support for Dagger Hilt, component hierarchies, SVG output format and inherited bindings support for @Subcomponent. For more details, see Releases.

Getting Started

Requirements

Scabbard uses GraphViz to generate graphs and hence requires dot command to be available for it to work.

Installation instructions

Install via homebrew.

brew install graphviz

Install via apt.

sudo apt-get install graphviz

Install via GraphViz installer or with Chocolatey by

choco install graphviz

After installation, verify installation by executing dot -V, example:

dot - graphviz version 2.38.0 (20140413.2041)

Installation

Gradle Plugin

Repositories

Scabbard artifacts are served via jcenter(). Please ensure jcenter() is added to your root build.gradle.

Using the plugins DSL:

plugins {
    id "scabbard.gradle" version "0.4.0"
}
plugins {
    id("scabbard.gradle") version "0.4.0"
}

or if you are using older versions of Gradle:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.dev.arunkumar:scabbard-gradle-plugin:0.4.0"
  }
}

apply plugin: "scabbard.gradle"
buildscript {
  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
  }
  dependencies {
    classpath("gradle.plugin.dev.arunkumar:scabbard-gradle-plugin:0.4.0")
  }
}

apply(plugin = "scabbard.gradle")

After applying the plugin, configure the plugin by adding a scabbard block:

scabbard {
    enabled true
}
scabbard {
    enabled = true
}
Configuring Scabbard for multi-module projects

For multi-module projects, it is sufficient to apply Scabbard plugin in root project's build.gradle file. Doing so will let the plugin configure all subprojects for graph generation.

In root build.gradle file:

apply plugin: "scabbard.gradle"

scabbard {
  enabled true
  outputFormat "svg"
}
apply(plugin = "scabbard.gradle")

scabbard {
  enabled = true
  outputFormat = "svg"
}

Success

That's it. Now after building the project, Scabbard would have generated dot and (png or svg) files for your Dagger components in your build folder. The default output directory is location defined by StandardLocation.CLASS_OUTPUT.

  • Java : build/classes/java/$sourceSet/scabbard
  • Kotlin : build/tmp/kapt3/classes/$sourceSet/scabbard

Android Studio/Idea Plugin

Scabbard also ships an IDE plugin to open generated images directly from your source code via gutter icons. Please install plugins from File > Preferences/Settings > Plugins > Market Place > Search for "Scabbard" > Install and Restart.

Alternatively you could download the plugin zip file directly from releases and install via File > Preferences/Settings > Plugins > Gear ⚙ > Install from Disk and point to zip file.

Success

The plugin should automatically add an icon next to @Component, @Subcomponent, @Module or @ContributesAndroidInjector as soon as project is indexed.

Other build systems

Scabbard at its core is just an annotation processor and as long as it is available alongside Dagger in the classpath, it should generate images. For configuring other build systems, please see setup guide.

Resources

License

Copyright 2020 Arunkumar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.