Guest User

resources.gradle

a guest
Feb 18th, 2015
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.27 KB | None | 0 0
  1. buildscript {
  2.     repositories {
  3.         mavenCentral()
  4.     }
  5.     dependencies {
  6.         classpath 'org.apache.commons:commons-lang3:3.3.2'
  7.     }
  8. }
  9.  
  10. // workaround, see https://code.google.com/p/android/issues/detail?id=136013
  11. import org.apache.commons.lang3.StringUtils
  12. gradle.projectsEvaluated {
  13.     def variants = android.applicationVariants.collect()
  14.  
  15.     tasks.withType(Test) { task ->
  16.         try {
  17.             variants.each { variant ->
  18.                 def buildTypeName = variant.buildType.name.capitalize()
  19.  
  20.                 def productFlavorNames = variant.productFlavors.collect { it.name.capitalize() }
  21.                 if (productFlavorNames.isEmpty()) {
  22.                     productFlavorNames = [""]
  23.                 }
  24.                 def productFlavorName = productFlavorNames.join('')
  25.                 def flavor = StringUtils.uncapitalize(productFlavorName)
  26.  
  27.                 def variationName = "${productFlavorName}${buildTypeName}"
  28.  
  29.                 if (task.name.contains(variationName)) {
  30.                     def variationPath = variant.buildType.name;
  31.  
  32.                     if (StringUtils.isNotEmpty(productFlavorName)) {
  33.                         variationPath = StringUtils.uncapitalize(productFlavorName) + "/" + variationPath
  34.                     }
  35.  
  36.                     def copyTestResourcesTask = project.tasks.create("copyTest${variationName}Resources", Copy)
  37.                     copyTestResourcesTask.from("${projectDir}/src/test/resources")
  38.                     copyTestResourcesTask.into("${buildDir}/intermediates/classes/test/${variationPath}")
  39.  
  40.                     // Makes the test task depend on the copy test resource variation task
  41.                     task.dependsOn(copyTestResourcesTask)
  42.  
  43.                     def copyResourcesTask = project.tasks.create("copy${variationName}Resources", Copy)
  44.                     copyResourcesTask.from("${projectDir}/src/main/resources")
  45.                     copyResourcesTask.into("${buildDir}/intermediates/classes/${variationPath}")
  46.  
  47.                     task.dependsOn(copyResourcesTask)
  48.  
  49.                     variants.remove(variant)
  50.  
  51.                     throw new Exception("Break") // Breaking the loop
  52.                 }
  53.             }
  54.         } catch (Exception e) {} // Just drop the exception
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment