Skip to content

Commit

Permalink
Initial implementation. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored Mar 4, 2018
1 parent ea86be5 commit 3f05f44
Show file tree
Hide file tree
Showing 41 changed files with 1,624 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .buildscript/deploy_snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# Deploy a jar, source jar, and javadoc jar to Sonatype's snapshot repo.
#
# Adapted from https://coderwall.com/p/9b_lfq and
# http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ and
# https://github.com/JakeWharton/RxBinding/blob/master/.buildscript/deploy_snapshot.sh

SLUG="vanniktech/gradle-dependency-graph-generator-plugin"
JDK="oraclejdk8"
BRANCH="master"

set -e

if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then
echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'."
elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then
echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'."
elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Skipping snapshot deployment: was pull request."
elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then
echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'."
else
echo "Deploying snapshot..."
./gradlew uploadArchives
echo "Snapshot deployed!"
fi
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
indent_size=2
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gradle/
build/
out/

.idea/
*.iml
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
language: groovy

groovy:
- 2.3.6
- 2.3.9

jdk:
- oraclejdk8

before_install:
- pip install --user codecov

install: true

script: ./gradlew clean build

after_success:
- codecov
- .buildscript/deploy_snapshot.sh

env:
global:
- secure: "fo9HUps/nNCI2bW9yzGCB79lhh0EWBPXz9WBro50AT2Fm1E/ofVP2cZG1ZP8hFmt1oJxaRwHuzn6Pq2zNd/b0wuM7xbhnBiWaBkoguYS62N536xSJVi0xvM6VM/oSDqClS1WNH8f44fXB8JB68NwP31mUSc0DC5nJd9MUA2LZEQ8Abj9l04Cu/Iq1CjRi9u0wxkbK2A8/cqjfzfSS63G0E1Z9K+PG8rH+yB4eQK3mfNh+gDiI3Jyc93xM7oahRlGv1nCVdVYvRQG/AvRZQ4EF8UuMP73o4XisBBS2AfGdDUXSi+v3XS18Vz41ynNm4tyF/443M1sSRAz1LGWArGKehR6WG8PJB26K0Ag7WZLkSRzu58Uz6dNNcjztrUK+PUuvEuLK1WKjeeqLCEDCVgWT9ujQE/RFMzXaT6rPLP1hnLnWitUU6DUJb5A/JB0lo9lBt6PjTM8RXY7K3x7xV3lVnJDKVTv1EXe5hk2wZxyCtIqR0F3h6E3QIDMC0SFFYPvz7eiiwStIDv7QIZw594jt/xbM94fxGziSP+Ti1mP2GKAPfEtNea6+XVMN4jJgSPpT8vL5vW54WhHAWUkDPL+q/V+lMGuloRN+AS/LOWTX8lF0YF9vO5HmhV8UY6eBEXUhOuSRZBW1RqMEz+yDpS8Tu7eA5lFDmnnheOtledsiQA="
- secure: "pNKrYMTjU0/Qyn1AG8YnPkxR3q8l61Z34pISGUr9c7sQK9hMiZ45dGYkqNmAoaK/lsiU6hvIOo7DCsxij4RnyLZZmUrrMtr2P9Vw1RxJjoPFtygQ0QVMT+9BE1Zynb//HyaJhVd+S4AYUBtuLs6tn78FkDmRCF9ZVu7B91kOdawIx9bgeJ2kHMileCe3Gpbcp/4/C/umD6xIcV3v6UUJCRKnEMGFj9BerLZHQRwiE18Bjz86nHnrQZEaM0gV1ZSKfA3gINCR6BWboikkk8FpmieiGJIcsS6p8mdzrQ5QeBFzdwFnFi07vbG7U8SBtPFDAnOiyPw/qmInWaK+I2v92KI4jpDfKF1lRr/bxdxLVAowuj45uxoj6z0AiUm95YgnPP34/4yw7aaTz+sGd+5XTqQSvzDtU8mIko8iUcDTdsCZS589qZQFf6HbVPVGSO+3pKgbALg6QY6YJgI5D1uC6O2H/iOPhUaD/+Eujm4ETdlmXhvlZVF4wM+6qvK7m3ms7vEvhcC9Dg4UlIYFIiEYH/faxP2EogL9V6qR+4AjCfPkefq2DOHFrc6FmvJ8hYa7PAyfEKXdErJZob0HB9is5o6Y+IcrC73FswVYxnKAm2BJOfF/i4pGX/PhfkIpzuG4QtefGyCJYBYpG68mdkPPg/wveQeun+R6EKXiWnIqqSM="

branches:
except:
- gh-pages

notifications:
email: false

sudo: false

cache:
directories:
- $HOME/.gradle
- $HOME/.m2
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

Version 0.2.0 *(In development)*
--------------------------------

Version 0.1.0 *(2018-03-04)*
----------------------------

- Initial release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
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.
limitations under the License.
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# gradle-dependency-graph-generator-plugin

[![Build Status](https://travis-ci.org/vanniktech/gradle-dependency-graph-generator-plugin.svg?branch=master)](https://travis-ci.org/vanniktech/gradle-dependency-graph-generator-plugin?branch=master)
[![Codecov](https://codecov.io/github/vanniktech/gradle-dependency-graph-generator-plugin/coverage.svg?branch=master)](https://codecov.io/github/vanniktech/gradle-dependency-graph-generator-plugin?branch=master)
[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)

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

# Set up

```groovy
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](https://plugins.gradle.org/plugin/com.vanniktech.dependency.graph.generator)

### Snapshots

Can be found [here](https://oss.sonatype.org/#nexus-search;quick~gradle-dependency-graph-generator-plugin). Current one is:

```groovy
classpath "com.vanniktech:gradle-dependency-graph-generator-plugin:0.2.0-SNAPSHOT"
```

## 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](https://play.google.com/store/apps/details?id=com.vanniktech.chessclock).

![Example graph.](example.png)

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](./src/main/kotlin/com/vanniktech/dependency/graph/generator/DependencyGraphGeneratorExtension.kt) 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.

```groovy
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.](example-firebase.png)

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

```groovy
dependencyGraphGenerator {
generators = [ Generator.ALL, firebaseGenerator ]
}
```
# License

Copyright (C) 2018 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0
133 changes: 133 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
buildscript {
ext.kotlinVersion = '1.2.30'

repositories {
jcenter()
google()
gradlePluginPortal()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.gradle.publish:plugin-publish-plugin:0.9.10'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.9.0'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.11.0'
}
}

apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
apply plugin: 'kotlin'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.vanniktech.code.quality.tools'
apply plugin: 'com.vanniktech.android.junit.jacoco'
apply plugin: 'com.gradle.plugin-publish'

codeQualityTools {
ktlint {
toolVersion = '0.18.0'
}
detekt {
toolVersion = '1.0.0.RC6-3'
}
findbugs {
enabled = false
}
pmd {
enabled = false
}
checkstyle {
enabled = false
}
cpd {
enabled = false
}
errorProne {
enabled = false
}
}

gradlePlugin {
plugins {
graphGeneratorDependencyPlugin {
id = 'com.vanniktech.dependency.graph.generator'
implementationClass = 'com.vanniktech.dependency.graph.generator.DependencyGraphGeneratorPlugin'
}
}
}

repositories {
jcenter()
google()
gradlePluginPortal()
}

dependencies {
implementation localGroovy()
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation gradleApi()

testImplementation 'junit:junit:4.12'
testImplementation 'org.assertj:assertj-core:3.9.1'
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
}

sourceCompatibility = JavaVersion.VERSION_1_7

group = GROUP
version = VERSION_NAME

pluginBundle {
website = POM_URL
vcsUrl = POM_SCM_URL

plugins {
dependencyGraphGenerator {
id = 'com.vanniktech.dependency.graph.generator'
displayName = POM_NAME
tags = ['gradle', 'graph', 'dependencies', 'graphviz', 'dot']
description = POM_DESCRIPTION
}
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.6'
distributionType = Wrapper.DistributionType.ALL
}

task groovydocJar(type: Jar, dependsOn: groovydoc) {
classifier = 'groovydoc'
from groovydoc.destinationDir
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives jar
archives groovydocJar
archives javadocJar
archives sourcesJar
}

apply from: file('gradle/gradle-mvn-push.gradle')

apply plugin: 'maven-publish'

publishing {
publications {
main(MavenPublication) {
from components.java
artifact sourcesJar
}
}
}
19 changes: 19 additions & 0 deletions code_quality_tools/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
failFast: true

potential-bugs:
UnsafeCast:
active: false # We know what we're doing.
LateinitUsage:
active: false # We know what we're doing.

style:
TopLevelPropertyNaming:
active: false
MaxLineLength:
active: false

comments:
UndocumentedPublicClass:
active: false
UndocumentedPublicFunction:
active: false
Binary file added example-firebase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
GROUP=com.vanniktech
VERSION_NAME=0.2.0-SNAPSHOT

POM_ARTIFACT_ID=gradle-dependency-graph-generator-plugin
POM_NAME=Gradle Graph Generator Plugin
POM_PACKAGING=jar

POM_DESCRIPTION=Gradle plugin that generates dependency graphs from your project.
POM_INCEPTION_YEAR=2018

POM_URL=http://github.com/vanniktech/gradle-dependency-graph-generator-plugin/
POM_SCM_URL=http://github.com/vanniktech/gradle-dependency-graph-generator-plugin/
POM_SCM_CONNECTION=scm:git:git://github.com/vanniktech/gradle-dependency-graph-generator-plugin.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/vanniktech/gradle-dependency-graph-generator-plugin.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=vanniktech
POM_DEVELOPER_NAME=Niklas Baudy
Loading

0 comments on commit 3f05f44

Please sign in to comment.