From 296e8ab79356bd45868cea082c5738c3c0d1dbbf Mon Sep 17 00:00:00 2001 From: Claudiu-Vlad Ursache Date: Thu, 11 Aug 2022 09:37:30 +0200 Subject: [PATCH] Add example Gradle Task for gathering dependencies --- app/build.gradle | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 5685e4a35..de5b2c64a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -140,6 +140,42 @@ gatherDependencies { androidVariantName = 'appRelease' } +// -------------------- BEGIN EXAMPLE GRADLE TASK FOR GATHERING DEPENDENCIES +tasks.register('gatherDeps_fromAndroidVariant', Copy) { + def variantName = 'appRelease' + def outputDirectory = rootProject.buildDir.getAbsolutePath() + '/gatheredDependencies' + def availableVariants = android.applicationVariants.findAll() + def variant = availableVariants.find { it.name == variantName } + if (variant == null) { + throw new GradleException("Variant with name `$variantName` not found. Available variants: ${availableVariants.collect{ it.name }}") + } + def filesFromVariant = variant.getCompileClasspath(null).files + filesFromVariant.each { file -> + duplicatesStrategy = 'include' + from file + into outputDirectory + } +} + +tasks.register('gatherDeps_fromAndroidApis', Copy) { + def outputDirectory = rootProject.buildDir.getAbsolutePath() + '/gatheredDependencies' + def configurationName = 'androidApis' + def availableConfigurations = project.configurations.findAll() + def androidApisConfiguration = availableConfigurations.find { it.name == configurationName } + if (androidApisConfiguration == null) { + throw new GradleException("Configuration with name `$configurationName` not found. Available configurations: ${availableConfigurations.collect { it.name }}") + } + duplicatesStrategy = 'include' + from androidApisConfiguration + into outputDirectory +} + +tasks.register('gatherDeps', Copy) { + dependsOn('gatherDeps_fromAndroidVariant') + dependsOn('gatherDeps_fromAndroidApis') +} +// -------------------- END EXAMPLE GRADLE TASK FOR GATHERING DEPENDENCIES + dependencies { //noinspection GradleDependency coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.1.6')