Make library projects use their library dependencies.
Xavier Ducrohet [Thu, 20 Sep 2012 00:04:04 +0000 (17:04 -0700)]
Change-Id: I3064c4b759a3fbe7ce4fadd5fcb4695530045ea7

gradle/src/main/groovy/com/android/build/gradle/AndroidBasePlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidLibraryPlugin.groovy
gradle/src/main/groovy/com/android/build/gradle/AndroidPlugin.groovy

index a9f039a..cf56b32 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.android.build.gradle
 
+import com.android.build.gradle.internal.AndroidDependencyImpl
 import com.android.build.gradle.internal.AndroidSourceSet
 import com.android.build.gradle.internal.ApplicationVariant
 import com.android.build.gradle.internal.ProductFlavorData
@@ -28,6 +29,8 @@ import com.android.builder.VariantConfiguration
 import com.android.utils.ILogger
 import org.gradle.api.Project
 import org.gradle.api.Task
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.artifacts.ProjectDependency
 import org.gradle.api.logging.LogLevel
 import org.gradle.api.plugins.BasePlugin
 import org.gradle.api.plugins.JavaBasePlugin
@@ -449,4 +452,50 @@ abstract class AndroidBasePlugin {
         return returnTask
     }
 
+    PrepareDependenciesTask createPrepareDependenciesTask(ProductionAppVariant variant) {
+        // TODO - include variant specific dependencies too
+        def compileClasspath = project.configurations.compile
+
+        // TODO - fix this in Gradle
+        ensureConfigured(compileClasspath)
+
+        def prepareDependenciesTask = project.tasks.add("prepare${variant.name}Dependencies",
+                PrepareDependenciesTask)
+
+        // TODO - should be able to infer this
+        prepareDependenciesTask.dependsOn compileClasspath
+
+        // TODO - defer downloading until required
+        // TODO - build the library dependency graph
+        List<File> jars = []
+        List<AndroidDependencyImpl> bundles = []
+        compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
+            if (artifact.type == 'alb') {
+                def explodedDir = project.file(
+                        "$project.buildDir/exploded-bundles/$artifact.file.name")
+
+                bundles << new AndroidDependencyImpl(explodedDir)
+                prepareDependenciesTask.add(artifact.file, explodedDir)
+            } else {
+                jars << artifact.file
+            }
+        }
+
+        variant.config.androidDependencies = bundles
+
+        // TODO - attach jars
+        // TODO - filter bundles out of source set classpath
+
+        return prepareDependenciesTask
+    }
+
+    def ensureConfigured(Configuration config) {
+        config.allDependencies.withType(ProjectDependency).each { dep ->
+            project.evaluationDependsOn(dep.dependencyProject.path)
+            ensureConfigured(dep.projectConfiguration)
+        }
+    }
+
+
+
 }
index 256ef58..3b6155d 100644 (file)
@@ -92,13 +92,15 @@ class AndroidLibraryPlugin extends AndroidBasePlugin implements Plugin<Project>
                 defaultConfigData.productFlavor, defaultConfigData.androidSourceSet,
                 buildTypeData.buildType, buildTypeData.androidSourceSet,
                 VariantConfiguration.Type.LIBRARY)
-        // TODO: add actual dependencies
-        variantConfig.setAndroidDependencies(null)
 
         ProductionAppVariant variant = new ProductionAppVariant(variantConfig)
 
+        def prepareDependenciesTask = createPrepareDependenciesTask(variant)
+
         // Add a task to process the manifest(s)
         ProcessManifestTask processManifestTask = createProcessManifestTask(variant, DIR_BUNDLES)
+        // TODO - move this
+        processManifestTask.dependsOn prepareDependenciesTask
 
         // Add a task to create the BuildConfig class
         def generateBuildConfigTask = createBuildConfigTask(variant, null)
@@ -108,6 +110,8 @@ class AndroidLibraryPlugin extends AndroidBasePlugin implements Plugin<Project>
                 null /*crunchTask*/)
 
         def compileAidl = createAidlTask(variant)
+        // TODO - move this
+        compileAidl.dependsOn prepareDependenciesTask
 
         // Add a compile task
         createCompileTask(variant, null/*testedVariant*/, processResources, generateBuildConfigTask,
index 28302be..df2ab8e 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.android.build.gradle
 
-import com.android.build.gradle.internal.AndroidDependencyImpl
 import com.android.build.gradle.internal.BuildTypeData
 import com.android.build.gradle.internal.BuildTypeDsl
 import com.android.build.gradle.internal.ProductFlavorData
@@ -28,8 +27,6 @@ import com.android.builder.VariantConfiguration
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.Task
-import org.gradle.api.artifacts.Configuration
-import org.gradle.api.artifacts.ProjectDependency
 import org.gradle.api.plugins.BasePlugin
 
 class AndroidPlugin extends AndroidBasePlugin implements Plugin<Project> {
@@ -269,45 +266,4 @@ class AndroidPlugin extends AndroidBasePlugin implements Plugin<Project> {
     String getTarget() {
         return extension.target;
     }
-
-    PrepareDependenciesTask createPrepareDependenciesTask(ProductionAppVariant variant) {
-        // TODO - include variant specific dependencies too
-        def compileClasspath = project.configurations.compile
-
-        // TODO - fix this in Gradle
-        ensureConfigured(compileClasspath)
-
-        def prepareDependenciesTask = project.tasks.add("prepare${variant.name}Dependencies", PrepareDependenciesTask)
-
-        // TODO - should be able to infer this
-        prepareDependenciesTask.dependsOn compileClasspath
-
-        // TODO - defer downloading until required
-        // TODO - build the library dependency graph
-        List<File> jars = []
-        List<AndroidDependencyImpl> bundles = []
-        compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
-            if (artifact.type == 'alb') {
-                def explodedDir = project.file("$project.buildDir/exploded-bundles/$artifact.file.name")
-                bundles << new AndroidDependencyImpl(explodedDir)
-                prepareDependenciesTask.add(artifact.file, explodedDir)
-            } else {
-                jars << artifact.file
-            }
-        }
-
-        variant.config.androidDependencies = bundles
-
-        // TODO - attach jars
-        // TODO - filter bundles out of source set classpath
-
-        return prepareDependenciesTask
-    }
-
-    def ensureConfigured(Configuration config) {
-        config.allDependencies.withType(ProjectDependency).each { dep ->
-            project.evaluationDependsOn(dep.dependencyProject.path)
-            ensureConfigured(dep.projectConfiguration)
-        }
-    }
 }