Skip to content

Instantly share code, notes, and snippets.

@kibotu
Last active March 22, 2022 13:07
Show Gist options
  • Save kibotu/a4b248e5ca8b702ef5884c3ab9693f8f to your computer and use it in GitHub Desktop.
Save kibotu/a4b248e5ca8b702ef5884c3ab9693f8f to your computer and use it in GitHub Desktop.
list dependencies
android.applicationVariants.all { variant ->
tasks.register("listDependencies${variant.name.capitalize()}") {
outputs.upToDateWhen { project.rootProject.file("app/src/${variant.name}/assets/dependencies.txt").exists() }
description = "Depdencies for ${variant.name.capitalize()}"
dependsOn tasks.named("pre${variant.name.capitalize()}Build").get()
final String filePath = "${project.rootDir}/app/src/${variant.name}/assets/dependencies.txt"
def assetFolder = new File("${project.rootDir}/app/src/${variant.name}/assets/")
if (!assetFolder.exists())
assetFolder.mkdirs()
final def output = new File(filePath)
output.write("")
configurations.getByName("${variant.name}RuntimeClasspath").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
println "${it.moduleGroup}:${it.moduleName} -> ${it.moduleVersion}"
output.append("${it.moduleGroup}:${it.moduleName}:${it.moduleVersion}\n")
}
}
}
@kibotu
Copy link
Author

kibotu commented Dec 31, 2020

./gradlew listDependenciesDebug listDependenciesRelease

@RameshbabuJaga
Copy link

Really awesome. This helps me a lot. Thank you.

@kibotu
Copy link
Author

kibotu commented Nov 29, 2021

I've updated the task to gradle 7 and generating a file into the build variant asset folder, so you can parse it at runtime :)

@RameshbabuJaga
Copy link

Hi kibotu. i am getting following error.

Failed to notify project evaluation listener.

java.lang.IllegalArgumentException: Cannot change attributes of dependency configuration ':app:releaseUnitTestCompileClasspath' after it has been resolved
KotlinJvmAndroidCompilation with name 'releaseUnitTest' not found.

@kibotu
Copy link
Author

kibotu commented Mar 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment