Last active
July 18, 2022 12:41
-
-
Save kibotu/a2bc6f154518fba633a87273cf024dcd to your computer and use it in GitHub Desktop.
Generating Dependencies for different build variants.
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
/** | |
* Generates a text file containing dependencies for different build variants | |
* and saves them into the respective variant asset folder. | |
* Also deletes files on clean. | |
* | |
* Can be safely used with <code>org.gradle.unsafe.configuration-cache=true</code> | |
*/ | |
android.applicationVariants.all { variant -> | |
def name = variant.name | |
def nameCapitalized = name.capitalize() | |
preBuild.dependsOn tasks.register("list${nameCapitalized}Dependencies") { | |
outputs.file(project.rootProject.file("app/src/$name/assets/dependencies.txt")) | |
def dependencies = configurations | |
.getByName("${name}RuntimeClasspath") | |
.getResolvedConfiguration() | |
.getFirstLevelModuleDependencies() | |
.collect { | |
"${it.moduleGroup}:${it.moduleName}:${it.moduleVersion}\n" | |
} | |
.sort() | |
doLast { | |
description = "Generate ${outputs.files.singleFile}" | |
println(description) | |
dependencies.each { | |
outputs.files.singleFile.append(it) | |
} | |
} | |
} | |
clean { | |
delete project.rootProject.file("app/src/$name/assets/dependencies.txt") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment