• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package org.robolectric.gradle
2
3import org.gradle.api.JavaVersion
4import org.gradle.api.Plugin
5import org.gradle.api.Project
6import org.gradle.api.tasks.compile.JavaCompile
7
8class RoboJavaModulePlugin implements Plugin<Project> {
9    Closure doApply = {
10        apply plugin: "java-library"
11
12        def skipErrorprone = System.getenv('SKIP_ERRORPRONE') == "true"
13        if (!skipErrorprone) {
14          apply plugin: "net.ltgt.errorprone"
15          project.dependencies {
16            errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
17            errorproneJavac("com.google.errorprone:javac:$errorproneJavacVersion")
18          }
19        }
20
21        apply plugin: AarDepsPlugin
22
23        sourceCompatibility = JavaVersion.VERSION_1_8
24        targetCompatibility = JavaVersion.VERSION_1_8
25
26        tasks.withType(JavaCompile) { task ->
27            sourceCompatibility = JavaVersion.VERSION_1_8
28            targetCompatibility = JavaVersion.VERSION_1_8
29
30            // Show all warnings except boot classpath
31            configure(options) {
32                if (System.properties["lint"] != null && System.properties["lint"] != "false") {
33                    compilerArgs << "-Xlint:all"        // Turn on all warnings
34                }
35                compilerArgs << "-Xlint:-options"       // Turn off "missing" bootclasspath warning
36                encoding = "utf-8"                      // Make sure source encoding is UTF-8
37            }
38
39        }
40
41        ext.mavenArtifactName = project.path.substring(1).split(/:/).join("-")
42
43        task('provideBuildClasspath', type: ProvideBuildClasspathTask) {
44            File outDir = project.sourceSets['test'].output.resourcesDir
45            outFile = new File(outDir, 'robolectric-deps.properties')
46        }
47
48        tasks['test'].dependsOn provideBuildClasspath
49
50        test {
51            exclude "**/*\$*" // otherwise gradle runs static inner classes like TestRunnerSequenceTest$SimpleTest
52
53            // TODO: DRY up code with AndroidProjectConfigPlugin...
54            testLogging {
55                exceptionFormat "full"
56                showCauses true
57                showExceptions true
58                showStackTraces true
59                showStandardStreams true
60                events = ["failed", "skipped"]
61            }
62
63            minHeapSize = "1024m"
64            maxHeapSize = "8192m"
65
66            if (System.env['GRADLE_MAX_PARALLEL_FORKS'] != null) {
67                maxParallelForks = Integer.parseInt(System.env['GRADLE_MAX_PARALLEL_FORKS'])
68            }
69
70            def forwardedSystemProperties = System.properties
71                    .findAll { k,v -> k.startsWith("robolectric.") }
72                    .collect { k,v -> "-D$k=$v" }
73            jvmArgs = forwardedSystemProperties
74
75            doFirst {
76                if (!forwardedSystemProperties.isEmpty()) {
77                    println "Running tests with ${forwardedSystemProperties}"
78                }
79            }
80        }
81    }
82
83    @Override
84    void apply(Project project) {
85        doApply.delegate = project
86        doApply.resolveStrategy = Closure.DELEGATE_ONLY
87        doApply()
88    }
89}
90