Detecting unused projects dependencies

I have a multiproject build with two projects: ProjA and ProjB.

ProjB has a compile dependency on ProjA. The ProjB build.gradle has:

dependencies {
    compile project(':ProjA')  // depend on the other project
    compile 'commons-io:commons-io:2.4'
    testCompile 'junit:junit:4.12'


When I do the command below, I see the dependency on ProjA from ProjB:

gradle -q dependencies ProjB:dependencies --configuration compile

Root project

No configurations

Project :ProjB

compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- log4j:log4j:1.2.16
+--- project :ProjA
|    \--- log4j:log4j:1.2.16
\--- commons-io:commons-io:2.4

However, there is no real dependency in the source code for this project. I can remove ProjA as a dependency in ProjB build.gradle. So in other words, how do I find unused/not needed project dependencies? This is sort of like the common use-case of trying to find unused jars in the classpath.
I inherited some legacy code and their build scripts are a mess…but legacy is what it is. :sweat_smile:

1 Like

After a quick search I found that

Does that help?

Hello. Thanks for the response. I tried the nebula-lint-plugin. It only shows unused jar dependencies. This is what I added:

apply plugin: 'nebula.lint'

gradleLint {

rules +=  'unused-dependency' 


I’m interested in finding unused/not needed projects. I think if the unused project brings in unused jars, and those jars are reported as unused dependencies, that would be sufficient.

This is published Gradle Plugin that I hope should work pretty well for identifying unused dependencies GitHub - Faire/gradle-kotlin-buildozer: Find unnecessary Gradle build file dependencies in Kotlin projects. It does work for unused projects (not just external dependencies). It also supports both Gradle and Kotlin DSLs