-
Notifications
You must be signed in to change notification settings - Fork 90
/
copyDeps.gradle
48 lines (44 loc) · 2.12 KB
/
copyDeps.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Taken from https://gist.github.com/n-belokopytov/d44949590748b096c1a497008b761d04
*/
android.libraryVariants.all { variant ->
task "copyDependencies${variant.name.capitalize()}"() {
outputs.upToDateWhen { false }
doLast {
println "Executing copyDependencies${variant.name.capitalize()}"
variant.getCompileClasspath().each { fileDependency ->
def sourcePath = fileDependency.absolutePath
def destinationPath = project.projectDir.path + "/build/dependencies/${variant.name}/"
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 dependencyAarNameRegexResult = (sourcePath =~ /.*\/(.*)\.aar\/.*\/jars\/classes\.jar/)
if (dependencyAarNameRegexResult.size() > 0) {
dependencyName = dependencyAarNameRegexResult[0][1]
println "Exploded AAR found : ${dependencyName}"
}
} else {
def dependencyJarNameRegexResult = (sourcePath =~ /.*\/caches\/[^\/]+\/[^\/]+\/(.*)\/.*\/.*\.jar/)
if (dependencyJarNameRegexResult.size() > 0) {
dependencyName = (dependencyJarNameRegexResult[0][1]).replace("/","-")
println "Jar found : ${dependencyName}"
}
}
copy {
from sourcePath
into destinationPath
rename { String filename ->
if (filename.contains(".jar") && dependencyName != null) {
dependencyName = "${dependencyName}.jar"
println "Renaming dependency file to : ${dependencyName}"
return dependencyName
}
return filename
}
}
}
}
}
}