1import org.gradle.api.DefaultTask 2import org.gradle.api.Project 3import org.gradle.api.tasks.OutputFile 4import org.gradle.api.tasks.TaskAction 5 6class ProvideBuildClasspathTask extends DefaultTask { 7 @OutputFile File outFile 8 9 @TaskAction 10 public void writeProperties() throws Exception { 11 final List<String> paths = new ArrayList<>() 12 13 project.rootProject.allprojects.each { Project otherProject -> 14 def match = otherProject.name =~ /shadows\/(.*)/ 15 if (match.matches()) { 16 def artifactName = "${otherProject.group}:${otherProject.mavenArtifactName}:${otherProject.version}" 17 File classesDir = otherProject.sourceSets['main'].output.classesDir 18 File resourcesDir = otherProject.sourceSets['main'].output.resourcesDir 19 paths << "${artifactName.replaceAll(/:/, '\\\\:')}: ${classesDir}:${resourcesDir}" 20 } 21 } 22 23 AndroidSdk.ALL_SDKS.each { androidSdk -> 24 def config = project.configurations.create("sdk${androidSdk.apiLevel}") 25 project.dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.coordinates) 26 paths << "${androidSdk.coordinates.replaceAll(/:/, '\\\\:')}: ${config.files.join(':')}" 27 } 28 29 File outDir = outFile.parentFile 30 if (!outDir.directory) outDir.mkdirs() 31 outFile.withPrintWriter { out -> 32 out.println("# GENERATED by ${this} -- do not edit") 33 paths.each { path -> out.println path } 34 } 35 } 36} 37