@@ -20,8 +20,7 @@ import groovy.json.JsonSlurper
2020import java.nio.file.Files
2121import java.nio.file.Paths
2222import java.nio.file.StandardCopyOption
23- import java.util.regex.Matcher
24- import java.util.regex.Pattern
23+ import groovy.io.FileType
2524import java.security.MessageDigest
2625import javax.inject.Inject
2726apply plugin : " com.android.application"
@@ -518,60 +517,61 @@ class EmptyRunnable implements Runnable {
518517}
519518
520519// Discover all jars and dynamically create tasks for the extraction of each of them
521- def allJars = []
520+ project . ext . allJars = []
522521afterEvaluate { project ->
523522 def buildType = project. selectedBuildType == " release" ? " Release" : " Debug"
524523 def jars = []
525- Pattern pattern = Pattern . compile(" ^(.+)${ buildType} CompileClasspath\$ " )
526524 def artifactType = Attribute . of(' artifactType' , String )
527525 configurations. all { config ->
528- Matcher matcher = pattern. matcher(config. name)
529- if (matcher. find() || config. name == " ${ buildType.toLowerCase()} CompileClasspath" ) {
526+ if (config. name == " ${ buildType.toLowerCase()} RuntimeClasspath" ) {
530527 config. incoming. artifactView {
531528 attributes {
532529 it. attribute(artifactType, ' jar' )
533530 }
534531 }. artifacts. each {
535- def jar = it. file;
536- if (! jars. contains(jar)) {
537- jars. add(jar)
538- def destDir = md5(jar. path);
539- def outputDir = new File (Paths . get(extractedDependenciesDir, destDir). normalize(). toString())
540-
541- def taskName = " extract_${ jar.name} _to_${ destDir} "
542- logger. debug(" Creating dynamic task ${ taskName} " )
543-
544- // Add discovered jars as dependencies of cleanupAllJars.
545- // This is cruicial for cloud builds because they are different
546- // on each incremental build (as each time the gradle user home
547- // directory is a randomly generated string)
548- cleanupAllJars. inputs. files jar
549-
550- task " ${ taskName} " (type : WorkerTask ) {
551- dependsOn cleanupAllJars
552- extractAllJars. dependsOn it
553-
554- // This dependency seems redundant but probably due to some Gradle issue with workers,
555- // without it `runSbg` sporadically starts before all extraction tasks have finished and
556- // fails due to missing JARs
557- runSbg. dependsOn it
558-
559- inputs. files jar
560- outputs. dir outputDir
561-
562- doLast {
563- // Runing in parallel no longer seems to bring any benefit.
564- // It mattered only when we were extracting JARs from AARs.
565- // To try it simply remove the following comments.
566- // workerExecutor.submit(EmptyRunnable.class) {
567- explodeAar(jar, outputDir)
568- // }
569- }
570- }
571- allJars. add([file : jar, outputDir : outputDir])
572- }
532+ processJar(it. file, jars)
533+ }
534+ }
535+ }
536+ }
537+
538+ def processJar (File jar , jars ) {
539+ if (! jars. contains(jar)) {
540+ jars. add(jar)
541+ def destDir = md5(jar. path)
542+ def outputDir = new File (Paths . get(extractedDependenciesDir, destDir). normalize(). toString())
543+
544+ def taskName = " extract_${ jar.name} _to_${ destDir} "
545+ logger. debug(" Creating dynamic task ${ taskName} " )
546+
547+ // Add discovered jars as dependencies of cleanupAllJars.
548+ // This is cruicial for cloud builds because they are different
549+ // on each incremental build (as each time the gradle user home
550+ // directory is a randomly generated string)
551+ cleanupAllJars. inputs. files jar
552+
553+ task " ${ taskName} " (type : WorkerTask ) {
554+ dependsOn cleanupAllJars
555+ extractAllJars. dependsOn it
556+
557+ // This dependency seems redundant but probably due to some Gradle issue with workers,
558+ // without it `runSbg` sporadically starts before all extraction tasks have finished and
559+ // fails due to missing JARs
560+ runSbg. dependsOn it
561+
562+ inputs. files jar
563+ outputs. dir outputDir
564+
565+ doLast {
566+ // Runing in parallel no longer seems to bring any benefit.
567+ // It mattered only when we were extracting JARs from AARs.
568+ // To try it simply remove the following comments.
569+ // workerExecutor.submit(EmptyRunnable.class) {
570+ explodeAar(jar, outputDir)
571+ // }
573572 }
574573 }
574+ project. ext. allJars. add([file : jar, outputDir : outputDir])
575575 }
576576}
577577
@@ -583,7 +583,7 @@ task cleanupAllJars {
583583 outputs. files cleanupAllJarsTimestamp
584584
585585 doLast {
586- def allDests = allJars* . outputDir* . name;
586+ def allDests = project . ext . allJars* . outputDir* . name;
587587 def dir = new File (extractedDependenciesDir)
588588 if (dir. exists()) {
589589 dir. eachDir {
0 commit comments