Skip to content

mjustin/gradle-dependency-analyze

 
 

Repository files navigation

gradle-dependency-analyze

Download Build Status

Dependency analysis plugin for gradle.

This plugin is based on the work in a gist at https://gist.github.com/anonymous/4334439, if you're the original author, thank you, and please let me know.

This plugin attempts to replicate the functionality of the maven dependency plugin's analyze goals which fail the build if dependencies are declared but not used or used but not declared.

The plugin is available from the JCenter repository, so it can be added to your build with the following:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.1.0'
  }
}

apply plugin: 'java'
// Dependency analysis plugin must be applied after the java plugin.
apply plugin: 'ca.cutterslade.analyze'

Tasks

This plugin will add three tasks to your project: analyzeClassesDependencies, analyzeTestClassesDependencies, and analyzeDependencies.

analyzeClassesDependencies

This task depends on the classes task and analyzes the dependencies of the main source set's output directory. This ensures that all dependencies of the classes are declared in the compile, compineOnly, or provided configuration. It also ensures the inverse, that all of the dependencies of these configurations are used by classes; use of the permitUnusedDeclared configuration allows for exceptions to this restriction.

analyzeTestClassesDependencies

This task depends on the testClasses task and analyzes the dependencies of the test source set's output directory. This ensures that all dependencies of the classes are declared in the testCompile or testCompineOnly configuration. It also ensures the inverse, that all of the dependencies of these configurations are used by classes; use of the permitTestUnusedDeclared configuration allows for exceptions to this restriction.

analyzeDependencies

This task depends on the analyzeClassesDependencies and analyzeTestClassesDependencies tasks, and does nothing on its own. A dependency on this task is added to the check task.

Configurations

This plugin adds two configurations which may be used to define dependencies which should be handled in a special way. These configurations have no impact on the build outside of this plugin.

  • permitUnusedDeclared
  • permitTestUnusedDeclared

Adding dependencies to one of these configurations causes the dependency analyzer to ignore cases where the dependencies declared but not used.

Task Configuration

The plugin is not especially configurable, but each task can be configured to log a warning about dependency issues rather than breaking the build like so:

analyzeClassesDependencies {
  justWarn = true
}

Version 1.1

Version 1.1 of this plugin introduced a couple significant changes.

  • The plugin now supports the compileOnly and testCompileOnly configurations introduced by gradle in version 2.12. This feature was discussed in detail in a posting on the gradle blog. These configurations should generally be used where provided would have been used.
  • The permitUnusedDeclared and permitTestUnusedDeclared configurations were introduced to allow for specific exceptions to the restriction which requires all declared dependencies to be used.
  • If the project makes use of the provided configuration, these dependencies are now treated the same as the compile configuration; specifically, dependencies of the provided configuration must be used by compiled class files. Previously, the provided configuration was an exception to that rule, allowing for the type of exception now supported by the permitUnusedDeclared configuration.

Migration from 1.0

If you previously made use of the provided configuration, upgrading to version 1.1 of this plugin may cause dependency analysis failures, since the provided configuration is now treated in the same way as the compile configuration. After investigating these failures to ensure that they do not represent a misconfiguration of the project dependencies, the offending dependencies can be added to the permitUnusedDeclared configuration to suppress the failure.

About

Dependency analysis plugin for gradle

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 100.0%