1 import java.util.regex.Pattern
4 // Expose the per-object-directory configuration to all projects.
6 mozconfig = gradle.mozconfig
7 topsrcdir = gradle.mozconfig.topsrcdir
8 topobjdir = gradle.mozconfig.topobjdir
12 if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
14 url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
20 buildDir "${topobjdir}/gradle/build"
24 if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
26 url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
29 // For android-sdk-manager SNAPSHOT releases.
31 url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
36 classpath 'com.android.tools.build:gradle:2.1.3'
37 classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.4') {
38 // Without these, we get errors linting.
39 exclude module: 'guava'
42 classpath 'com.jakewharton.sdkmanager:gradle-plugin:1.5.0-SNAPSHOT'
43 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.1'
47 task generateCodeAndResources(type:Exec) {
48 workingDir "${topobjdir}"
50 commandLine mozconfig.substs.GMAKE
52 args "${topobjdir}/mobile/android/base"
55 // Only show the output if something went wrong.
56 ignoreExitValue = true
57 standardOutput = new ByteArrayOutputStream()
58 errorOutput = standardOutput
60 if (execResult.exitValue != 0) {
61 throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
66 // Skip unit test for all build variants, unless if it was specifically requested by user.
67 // The enabled property for the unit test tasks is reset based on the command line task names just before the task execution.
68 // I bet there is a easier/cleaner way to do this, but this gets the job done for now.
69 Pattern pattern = Pattern.compile('.*test(.+UnitTest)?.*')
70 boolean startTasksIncludeTest = gradle.startParameter.taskNames.any {
72 taskName.matches(pattern)
74 gradle.taskGraph.beforeTask {
76 if (task.name.matches(pattern)) {
77 task.enabled = startTasksIncludeTest
83 if (!hasProperty('android')) {
86 android.applicationVariants.all {
87 preBuild.dependsOn rootProject.generateCodeAndResources
89 android.libraryVariants.all {
90 preBuild.dependsOn rootProject.generateCodeAndResources
103 // Object directories take a huge amount of time for IntelliJ to index.
104 // Exclude them. Convention is that object directories start with obj.
105 // IntelliJ is clever and will not exclude the parts of the object
106 // directory that are referenced, if there are any. In practice,
107 // indexing the entirety of the tree is taking too long, so exclude all
109 def topsrcdirURI = file(topsrcdir).toURI()
110 excludeDirs += files(file(topsrcdir)
111 .listFiles({it.isDirectory()} as FileFilter)
112 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
113 .findAll({!it.equals('mobile/')}))
115 // If topobjdir is below topsrcdir, hide only some portions of that tree.
116 def topobjdirURI = file(topobjdir).toURI()
117 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
118 excludeDirs -= file(topobjdir)
119 excludeDirs += files(file(topobjdir).listFiles())
120 excludeDirs -= file("${topobjdir}/gradle")
123 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
124 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
129 task wrapper(type: Wrapper) {