Skip to content

IntershopCommunicationsAG/dependencyanalysis-gradle-plugin

Repository files navigation

Dependency Analysis Plugin

Note
Version 3.4.0 (and later) of this plugin will work with Gradle 4.5 (and later) and JDK 8.

Summary

This plugin identifies unused dependencies of a project and it detects duplicate classes in dependencies. A detailed result is written to a html report. It is possible to configure when the task should fail.

Usage

To apply the Dependency Analysis Plugin to your projects, add the following in your build script:

plugins {
    id 'com.intershop.gradle.dependencyanalysis' version '3.3.0'
}

dependencyAnalysis {
  reportsDir = file('reports')

  failOnDuplicates = true
  failOnUnusedFirstLevelDependencies = true
  failOnUsedTransitiveDependencies = true
  failOnUnusedTransitiveDependencies = false

  enabled = true
}

The task is available for Gradle’s Java plugin and also for the Java-Library plugin. Dependencies of the 'compile' configuration will be checked for the Java plugin. If the Java-Library is configured, dependencies of the configurations 'api' and the 'implementation' will be analyzed. But in this case it is not possible to analyze transitive dependencies separately.

Tasks

The Intershop Dependency Analysis plugin adds a task dependencyAnalysis to the project. Since this is a verification task, the task 'check' dependents on it.

Task name

Type

Description

dependencyAnalysis

com.intershop.gradle.analysis.tasks.DependencyAnalysisTask

This task runs the dependency validation.

Project Extension 'dependencyAnalysis'

This plugin adds an extension dependencyAnalysis to the project. This extension contains all plugin configurations.

Convention properties

Property Type Default value Description

reportsDir

File

<Base report dir>/dependencyAnalysis

Base dir for the reporting file.

failOnDuplicates

boolean

true

The build will fail if there are duplicate classes in the used dependency configuration.

failOnUnusedFirstLevelDependencies

boolean

true

The build will fail if there are unused dependencies configured.

failOnUsedTransitiveDependencies

boolean

true

If transitive dependencies are used, the build will fail.

failOnUnusedTransitiveDependencies

boolean

false

If unused transitive dependencies are available, the build will fail.

excludeDuplicatePatterns

List<String>

[]

List of exclude pattern for duplicates

excludeDependencyPatterns

List<String>

[]

List of exclude pattern for dependencies (pattern must contain also patterns for the version)

enabled

boolean

true

If this property is true, the task is added and the project will be verified.

sourceset

String

main

The name of the source set which is used for this check.

Please make sure that only compile dependencies can be correct evaluated. All configuration properties are optional.

Example Output

This is the example of the output if the task fails.

There are several dependency issues.
  Please check /build/reports/dependencyAnalysis/dependency-report.html for more information

If the task should not fail there is also an output:

-- Dependency Analysis
  There are duplicates (2)
  There are unused dependencies (1)

License

Copyright 2014-2016 Intershop Communications.

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

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.