Last active
July 19, 2021 18:29
-
-
Save rock3r/cf243af5d4e6482f784396b01f04b7ac to your computer and use it in GitHub Desktop.
Utility Gradle task to find where duplicate classes come from (for Gradle 4.1+)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// H/t to https://github.com/ethankhall/scripts/blob/master/gradle/find-file.gradle for the idea; | |
// this re-written version actually works in modern Gradle and Android Gradle plugins. | |
task findInDependencies { | |
doLast { | |
println() | |
def resolvableConfigs = project.getConfigurations() | |
.stream() | |
.filter { it.isCanBeResolved() } | |
resolvableConfigs.each { config -> | |
config.resolve() | |
.stream() | |
.filter { | |
//noinspection GroovyPointlessBoolean | |
zipTree(it) | |
.filter { it.name.startsWith 'Nonnegative' } // TODO replace `Nonnegative` with what you are looking for | |
.each { println " Match: $it.path" } | |
.toList() | |
.isEmpty() == false | |
} | |
.each { | |
println "Found in `$config.name: $it.name`\n" | |
} | |
} | |
} | |
} |
LeftShift has been deprecated and will no longer work with Gradle v5. This can be fixed by using this instead:
task findInDependencies {
doLast {
println()
def resolvableConfigs = project.getConfigurations()
.stream()
.filter { it.isCanBeResolved() }
resolvableConfigs.each { config ->
config.resolve()
.stream()
.filter {
//noinspection GroovyPointlessBoolean
zipTree(it)
.filter { it.name.startsWith 'Nonnegative' } // TODO replace `Nonnegative` with what you are looking for
.each { println " Match: $it.path" }
.toList()
.isEmpty() == false
}
.each {
println "Found in `$config.name: $it.name`\n"
}
}
}
}
Thanks, I have incorporated it in the main gist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is useful for when your build breaks because of errors such as
com.android.dex.DexException: Multiple dex files define L...;
.Common culprits are Findbugs 3.0.1 and its annotations that include the JSR305 annotations, such as
javax/annotation/Nonnegative
etc. In these cases you need to manually exclude those transitive dependencies from the all those that declare them, and re-declare them explicitly yourself. Thedependencies
task can be very useful to determine what top-level dependencies transitively include them.