Last active
March 22, 2022 13:07
-
-
Save kibotu/a4b248e5ca8b702ef5884c3ab9693f8f to your computer and use it in GitHub Desktop.
list dependencies
This file contains 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
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") | |
} | |
} | |
} |
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.
here is a more up-to-date version of this script
https://gist.github.com/kibotu/a2bc6f154518fba633a87273cf024dcd#file-generate_dependencies-gradle
cheers~
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)