mobile/android/gradle/build.gradle
author Nick Alexander <nalexander@mozilla.com>
Sun, 18 Oct 2015 17:05:29 -0700
changeset 268561 5165a60f02115564b69d5c8dbf6c995e25fc2fb3
parent 268559 d12ef59cbae5529866519f80a07138d1f8cc858d
child 268877 3fa48c9d205bc6628b74caf93716338935b48689
permissions -rw-r--r--
Bug 1216430 - Use Gradle version 2.7. r=sebastian DONTBUILD NPOTB

import java.util.regex.Pattern

allprojects {
    // Expose the per-object-directory configuration to all projects.
    ext {
        mozconfig = gradle.mozconfig
        topsrcdir = gradle.mozconfig.topsrcdir
        topobjdir = gradle.mozconfig.topobjdir
    }

    repositories {
        jcenter()
    }
}

buildDir "${topobjdir}/mobile/android/gradle/build"

buildscript {
    repositories {
        jcenter()

        // For spoon-gradle-plugin SNAPSHOT release.  This needs to go before
        // the snapshots repository, otherwise we find a remote 1.0.3-SNAPSHOT
        // that doesn't include nalexander's local changes.
        maven {
            url "file://${topsrcdir}/mobile/android/gradle/m2repo"
        }
        // For spoon SNAPSHOT releases.
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }

    dependencies {
        // Unit testing support was added in 1.1.0. IntelliJ 14.1.4 and Android
        // Studio 1.2.1.1 appear to work fine with plugin version 1.3.0.
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.3-SNAPSHOT') {
            // Without these, we get errors linting.
            exclude module: 'guava'
        }
    }
}

task generateCodeAndResources(type:Exec) {
    workingDir "${topobjdir}"

    commandLine mozconfig.substs.GMAKE
    args '-C'
    args "${topobjdir}/mobile/android/base"
    args 'gradle-targets'

    // Only show the output if something went wrong.
    ignoreExitValue = true
    standardOutput = new ByteArrayOutputStream()
    errorOutput = standardOutput
    doLast {
        if (execResult.exitValue != 0) {
            throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
        }
    }
}

// Skip unit test for all build variants, unless if it was specifically requested by user.
// The enabled property for the unit test tasks is reset based on the command line task names just before the task execution.
// I bet there is a easier/cleaner way to do this, but this gets the job done for now.
Pattern pattern = Pattern.compile('.*test(.+UnitTest)?.*')
boolean startTasksIncludeTest = gradle.startParameter.taskNames.any {
    taskName ->
        taskName.matches(pattern)
}
gradle.taskGraph.beforeTask {
    Task task ->
        if (task.name.matches(pattern)) {
            task.enabled = startTasksIncludeTest
        }
}

afterEvaluate {
    subprojects {
        if (!hasProperty('android')) {
            return
        }
        android.applicationVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources
        }
        android.libraryVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources
        }
    }
}

apply plugin: 'idea'

idea {
    project {
        languageLevel = '1.7'
    }
}

task wrapper(type: Wrapper) {
}