diff --git a/classpath.gradle b/classpath.gradle index c14af8e5..d15cedd6 100644 --- a/classpath.gradle +++ b/classpath.gradle @@ -1,109 +1,59 @@ -boolean isResolvable(Configuration conf) { - // isCanBeResolved was added in Gradle 3.3. Previously, all configurations were resolvable - if (Configuration.class.declaredMethods.any { it.name == 'isCanBeResolved' }) { - return conf.canBeResolved - } - return true -} - - -File getBuildCacheForDependency(File dependency) { - String name = dependency.getName() - String home = System.getProperty("user.home") - String gradleCache = home + File.separator + '.gradle' + File.separator + 'caches' + File.separator - if (file(gradleCache).exists()) { - String include = 'transforms*' + File.separator + '**' + File.separator + name + File.separator + '**' + File.separator + 'classes.jar' - return fileTree(dir: gradleCache, include: include).files.find { it.isFile() } - } else { - return zipTree(dependency).files.find { it.isFile() && it.name.endsWith('jar') } - } -} - task classpath { doLast { HashSet classpathFiles = new HashSet() - HashSet paths = new HashSet() - for (proj in allprojects) { - for (conf in proj.configurations) { - if (isResolvable(conf)) { - for (dependency in conf) { - classpathFiles += dependency - } + for (project in allprojects) { + if (project.hasProperty('android')) { + project.android.getBootClasspath().each { + classpathFiles += it } - } + if (project.android.hasProperty('applicationVariants')) { + project.android.applicationVariants.all { variant -> - def rjava = proj.getBuildDir().absolutePath + File.separator + "intermediates" + File.separator + "classes" + File.separator + "debug" - def rFiles = new File(rjava) - if (rFiles.exists()) { - classpathFiles += rFiles - } + def variantBase = variant.baseName.replaceAll("-", File.separator) - if (proj.hasProperty("android")) { - classpathFiles += proj.android.getBootClasspath() - if (proj.android.hasProperty("applicationVariants")) { - proj.android.applicationVariants.all { v -> - if (v.hasProperty("javaCompile")) { - classpathFiles += v.javaCompile.classpath - } - if (v.hasProperty("compileConfiguration")) { - v.compileConfiguration.each { dependency -> - classpathFiles += dependency - } - } - if (v.hasProperty("runtimeConfiguration")) { - v.runtimeConfiguration.each { dependency -> - classpathFiles += dependency - } - } - if (v.hasProperty("getApkLibraries")) { - println v.getApkLibraries() - classpathFiles += v.getApkLibraries() - } - if (v.hasProperty("getCompileLibraries")) { - classpathFiles += v.getCompileLibraries() - } - for (srcSet in v.getSourceSets()) { - for (dir in srcSet.java.srcDirs) { - paths += dir.absolutePath - } - } - } - } + def buildClasses = project.getBuildDir().absolutePath + + File.separator + "intermediates" + + File.separator + "classes" + + File.separator + variantBase + + classpathFiles += buildClasses + + def userClasses = project.getBuildDir().absolutePath + + File.separator + "intermediates" + + File.separator + "javac" + + File.separator + variant.baseName.replaceAll("-", File.separator) + + File.separator + "compile" + variantBase.capitalize() + "JavaWithJavac" + File.separator + "classes" - if (proj.android.hasProperty("libraryVariants")) { - proj.android.libraryVariants.all { v -> - classpathFiles += v.javaCompile.classpath.files - for (srcSet in v.getSourceSets()) { - for (dir in srcSet.java.srcDirs) { - paths += dir.absolutePath - } + classpathFiles += userClasses + + variant.getCompileClasspath().each { + classpathFiles += it } } } - } - - if (proj.hasProperty("sourceSets")) { - for (srcSet in proj.sourceSets) { - for (dir in srcSet.java.srcDirs) { - paths += dir.absolutePath + } else { + // Print the list of all dependencies jar files. + project.configurations.findAll { + it.metaClass.respondsTo(it, "isCanBeResolved") ? it.isCanBeResolved() : false + }.each { + it.resolve().each { + if (it.inspect().endsWith("jar")) { + classpathFiles += it + } else if (it.inspect().endsWith("aar")) { + // If the dependency is an AAR file we try to determine the location + // of the classes.jar file in the exploded aar folder. + def splitted = it.inspect().split("/") + def namespace = splitted[-5] + def name = splitted[-4] + def version = splitted[-3] + def explodedPath = "$project.buildDir/intermediates/exploded-aar/$namespace/$name/$version/jars/classes.jar" + classpathFiles += explodedPath } + } } } } - - HashSet computedPaths = new HashSet() - for (dependency in classpathFiles) { - if (dependency.name.endsWith("jar")) { - computedPaths += dependency - } else { - computedPaths += getBuildCacheForDependency(dependency) - } - } - - - computedPaths += paths - - def classpath = computedPaths.join(File.pathSeparator) + def classpath = classpathFiles.join(File.pathSeparator) println "CLASSPATH:" + classpath println "END CLASSPATH GENERATION" }