Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gradle script that generates a task to copy all build variant's dependencies to a certain directory for use with Nexus IQ Server. It copies exploded AARs too, renaming the classes.jar file into "<aar_dependency_name>.jar".
apply plugin: ''
android.applicationVariants.all { variant ->
task "copyDependencies${}"() {
outputs.upToDateWhen { false }
doLast {
println "Executing copyDependencies${}"
variant.getCompileClasspath().each { fileDependency ->
def sourcePath = fileDependency.absolutePath
def destinationPath = project.projectDir.path + "/build/dependencies/${}/"
println "Copying dependency:"
println sourcePath
//The monstrous regex that gets the name of the lib from it’s exploded .aar path
def dependencyName
if (sourcePath.contains("classes.jar")) {
def dependencyNameRegexResult = (sourcePath =~ /.*[\/\\](.*)\.aar[\/\\].*[\/\\]jars[\/\\]classes\.jar/)
if (dependencyNameRegexResult.size() > 0) {
dependencyName = dependencyNameRegexResult[0][1]
println "Exploded AAR found : ${dependencyName}"
copy {
from sourcePath
into destinationPath
rename {String filename ->
if (filename.contains("classes.jar") && dependencyName != null) {
dependencyName = "${dependencyName}.jar"
println "Renaming dependency file to : ${dependencyName}"
return dependencyName
return filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.