Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How to check for duplicate dependencies in project?

I am attempting to remove all out-of-date / unnecessary dependencies from my project.

When looking at the output of the allDeps task I can see that there are several dependencies that are replicated but the output is difficult to understand.

Is there a specific Gradle tool / task that I can use to get a clearer view of what dependencies I can remove?

like image 1000
java123999 Avatar asked Dec 14 '15 16:12

java123999


2 Answers

You can use ./gradlew projectName:dependencies to see a tree of all the dependencies of your project. Both that are repeated or with different versions are remarked in the different configurations and classpaths.

like image 84
droidpl Avatar answered Oct 08 '22 06:10

droidpl


WARNING: Unfortunately, the plugin fails to add its tasks to the gradle build for me using gradle 3.3. It still fails for gradle 4.3.1 (thanks to MoePad for reporting). The project seems to be not very active, so it might not work as expected.


For completeness: There is a gradle plugin available called dependency-checker which does "assist in validating project dependencies". Additional link to the gradle plugin page.

One of the tasks added is:

CheckDependencies

A Task used to validate that the build has no duplicate dependencies - a dependency with the same group and name, but with a different version. The build will be failed if any duplications are found.

It may help identifying duplicates/outdated dependencies as well.

Adding the plugin to your gradle build file:

plugins {
  id "com.stehno.gradle.dependency-checker" version "0.2.2"
}

This should add the following gradle tasks:

  • checkDependencies
  • checkAvailability

For details about configuration and what the tasks exactly do, please refer to the github page.

like image 24
AntiTiming Avatar answered Oct 08 '22 06:10

AntiTiming