This gradle plugin adds a task to your project that will create a graph of how your gradle modules depend on each other.
For example, this is the module graph of the Android project GameFrame:
Apply the gradle plugin on your root build.gradle file:
plugins {
id 'com.savvasdalkitsis.module-dependency-graph' version '<latest_version>'
}
legacy syntax:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.savvasdalkitsis:module-dependency-graph:<latest_version>"
}
}
apply plugin: "com.savvasdalkitsis.module-dependency-graph"From the command line, simply run:
./gradlew graphModulesThis will create a png of the dependency graph of your modules and open the image
You can specify a comma separated list of modules to include in the output. If this is specified the graph will contain only these modules and their dependants and dependencies. This can be helpful when trying to clean up a really complicated dependency tree and you need to focus on only a part of it.
./gradlew graphModules -PgraphFilter=core,presentation:api,networkYou can specify where the dot file and output file get created by specifying the following properties:
./gradlew graphModules -PdotFilePath={ABSOLUTE_PATH_TO_DOT_FILE} -PgraphOutputFilePath={ABSOLUTE_PATH_TO_OUTPUT_FILE} or in the gradle.properties file:
dotFilePath={ABSOLUTE_PATH_TO_DOT_FILE}
graphOutputFilePath={ABSOLUTE_PATH_TO_OUTPUT_FILE}
Apart from png, which is the default format, this plugin has support for other formats, like svg and any
other format that graphviz supports (can be found here):
./gradlew graphModules -PgraphOutputFormat=svg or in the gradle.properties file:
graphOutputFormat=svg
By default, the generated graph will be opened using the system's default app for handling the specified format. If you don't want this to happen, you can specify the following parameter:
./gradlew graphModules -PautoOpenGraph=false or in the gradle.properties file:
autoOpenGraph=false
By default, the command line tool dot will be used to transform an output defined in the
Gradle property graphOutputFormat. If you don't want this to happen,
you can specify the following parameter:
./gradlew graphModules -PtransformDot=false or in the gradle.properties file:
transformDot=false
You must have graphviz installed on your system in order to use this plugin. For more information on how to install it visit http://www.graphviz.org/
The plugin currently only works on macOS and Linux since it is in the very early stages (as reflected by its version number). Multi-platform support will be coming soon along with many customization options.
Copyright 2020 Savvas Dalkitsis
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.
