1package org.robolectric.gradle 2 3import org.gradle.api.Plugin 4import org.gradle.api.Project 5 6public class AndroidProjectConfigPlugin implements Plugin<Project> { 7 @Override 8 public void apply(Project project) { 9 project.android.testOptions.unitTests.all { 10 // TODO: DRY up code with RoboJavaModulePlugin... 11 testLogging { 12 exceptionFormat "full" 13 showCauses true 14 showExceptions true 15 showStackTraces true 16 showStandardStreams true 17 events = ["failed", "skipped"] 18 } 19 20 minHeapSize = "2048m" 21 maxHeapSize = "8192m" 22 23 if (System.env['GRADLE_MAX_PARALLEL_FORKS'] != null) { 24 maxParallelForks = Integer.parseInt(System.env['GRADLE_MAX_PARALLEL_FORKS']) 25 } 26 27 def forwardedSystemProperties = System.properties 28 .findAll { k,v -> k.startsWith("robolectric.") } 29 .collect { k,v -> "-D$k=$v" } 30 jvmArgs = forwardedSystemProperties 31 32 doFirst { 33 if (!forwardedSystemProperties.isEmpty()) { 34 println "Running tests with ${forwardedSystemProperties}" 35 } 36 } 37 } 38 39 project.task('provideBuildClasspath', type: ProvideBuildClasspathTask) { 40 File outDir = new File(project.buildDir, "generated/robolectric") 41 outFile = new File(outDir, 'robolectric-deps.properties') 42 43 project.android.sourceSets['test'].resources.srcDir(outDir) 44 } 45 46 project.afterEvaluate { 47 project.tasks.forEach { task -> 48 if (task.name.matches("process.*UnitTestJavaRes")) { 49 task.dependsOn "provideBuildClasspath" 50 } 51 } 52 } 53 } 54} 55