Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 1 | import android.support.doclava.DoclavaMultilineJavadocOptionFileOption |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 2 | import com.android.build.gradle.internal.coverage.JacocoReportTask |
| 3 | import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask |
| 4 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 5 | import android.support.checkapi.CheckApiTask |
| 6 | import android.support.checkapi.UpdateApiTask |
| 7 | import android.support.doclava.DoclavaTask |
| 8 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 9 | buildscript { |
| 10 | repositories { |
| 11 | maven { url '../../prebuilts/gradle-plugin' } |
| 12 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 13 | maven { url '../../prebuilts/tools/common/m2/internal' } |
Yigit Boyar | c9750a1 | 2016-01-06 17:28:55 -0800 | [diff] [blame] | 14 | maven { url "../../prebuilts/maven_repo/android" } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 15 | } |
| 16 | dependencies { |
Aurimas Liutikas | 5c6933b | 2016-09-20 09:55:40 -0700 | [diff] [blame] | 17 | // Keep gradle plugin version in sync with ub_supportlib-master manifest. |
Aurimas Liutikas | aca4aad | 2016-10-12 14:48:41 -0700 | [diff] [blame] | 18 | classpath 'com.android.tools.build:gradle:2.2.1' |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 19 | } |
| 20 | } |
| 21 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 22 | repositories { |
| 23 | maven { url '../../prebuilts/tools/common/m2/repository' } |
| 24 | } |
| 25 | |
| 26 | configurations { |
| 27 | doclava |
| 28 | } |
| 29 | |
| 30 | dependencies { |
| 31 | doclava project(':doclava') |
| 32 | } |
| 33 | |
Aurimas Liutikas | 98e56ad | 2016-11-15 11:09:50 -0800 | [diff] [blame] | 34 | gradle.ext.currentSdk = 'current' |
Aurimas Liutikas | ca81181 | 2016-10-17 10:24:10 -0700 | [diff] [blame] | 35 | ext.supportVersion = '25.1.0-SNAPSHOT' |
| 36 | ext.extraVersion = 40 |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 37 | ext.supportRepoOut = '' |
Aurimas Liutikas | 78449c1 | 2016-11-14 15:20:08 -0800 | [diff] [blame] | 38 | ext.buildToolsVersion = '24.0.1' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 39 | ext.buildNumber = Integer.toString(ext.extraVersion) |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 40 | |
Aurimas Liutikas | dfe7578 | 2016-08-03 14:27:20 -0700 | [diff] [blame] | 41 | ext.testRunnerVersion = '0.6-alpha' |
| 42 | ext.espressoVersion = '2.3-alpha' |
| 43 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 44 | // Enforce the use of prebuilt dependencies in all sub-projects. This is |
| 45 | // required for the doclava dependency. |
| 46 | ext.usePrebuilts = "true" |
| 47 | |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 48 | /* |
| 49 | * With the build server you are given two env variables. |
| 50 | * The OUT_DIR is a temporary directory you can use to put things during the build. |
| 51 | * The DIST_DIR is where you want to save things from the build. |
| 52 | * |
| 53 | * The build server will copy the contents of DIST_DIR to somewhere and make it available. |
| 54 | */ |
| 55 | if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) { |
Xavier Ducrohet | 4e04b7a | 2014-10-17 18:02:33 -0700 | [diff] [blame] | 56 | buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile() |
| 57 | project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile() |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 58 | |
| 59 | // the build server does not pass the build number so we infer it from the last folder of the dist path. |
| 60 | ext.buildNumber = project.ext.distDir.getName() |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 61 | } else { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 62 | buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build") |
| 63 | project.ext.distDir = file("${project.rootDir}/../../out/dist") |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 64 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 65 | |
Alan Viverette | 9b5fe93 | 2016-07-22 10:28:31 -0400 | [diff] [blame] | 66 | subprojects { |
| 67 | // Change buildDir first so that all plugins pick up the new value. |
| 68 | project.buildDir = project.file("$project.parent.buildDir/../$project.name/build") |
| 69 | } |
| 70 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 71 | ext.docsDir = new File(buildDir, 'javadoc') |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 72 | ext.supportRepoOut = new File(buildDir, 'support_repo') |
Yigit Boyar | f18d975 | 2015-12-01 13:45:28 -0800 | [diff] [blame] | 73 | ext.testApkDistOut = ext.distDir |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 74 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 75 | // Main task called by the build server. |
| 76 | task(createArchive) << { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 79 | // upload anchor for subprojects to upload their artifacts |
| 80 | // to the local repo. |
| 81 | task(mainUpload) << { |
| 82 | } |
| 83 | |
| 84 | // repository creation task |
| 85 | task createRepository(type: Zip, dependsOn: mainUpload) { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 86 | from project.ext.supportRepoOut |
| 87 | destinationDir project.ext.distDir |
Xavier Ducrohet | 9dc4480 | 2014-03-20 14:15:16 -0700 | [diff] [blame] | 88 | into 'm2repository' |
Xavier Ducrohet | fa38527 | 2014-11-14 13:12:09 -0800 | [diff] [blame] | 89 | baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber) |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 90 | } |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 91 | createArchive.dependsOn createRepository |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 92 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 93 | // prepare repository with older versions |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 94 | task unzipRepo(type: Copy) { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 95 | from "${project.rootDir}/../../prebuilts/maven_repo/android" |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 96 | into project.ext.supportRepoOut |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 99 | unzipRepo.doFirst { |
Xavier Ducrohet | 020e432 | 2014-03-18 16:41:30 -0700 | [diff] [blame] | 100 | project.ext.supportRepoOut.deleteDir() |
| 101 | project.ext.supportRepoOut.mkdirs() |
| 102 | } |
| 103 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 104 | // anchor for prepare repo. This is post unzip + sourceProp. |
| 105 | task(prepareRepo) << { |
| 106 | } |
| 107 | |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame^] | 108 | // lint every library |
| 109 | task(lint) << { |
| 110 | } |
| 111 | |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 112 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 113 | import com.google.common.io.Files |
| 114 | import com.google.common.base.Charsets |
| 115 | |
| 116 | task(createXml) << { |
| 117 | def repoArchive = createRepository.archivePath |
| 118 | def repoArchiveName = createRepository.archiveName |
| 119 | def size = repoArchive.length() |
| 120 | def sha1 = getSha1(repoArchive) |
| 121 | |
| 122 | def xml = |
| 123 | "<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\ |
| 124 | <sdk:extra>\n\ |
| 125 | <sdk:revision>\n\ |
| 126 | <sdk:major>${project.ext.extraVersion}</sdk:major>\n\ |
| 127 | </sdk:revision>\n\ |
| 128 | <sdk:vendor-display>Android</sdk:vendor-display>\n\ |
| 129 | <sdk:vendor-id>android</sdk:vendor-id>\n\ |
| 130 | <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\ |
| 131 | <sdk:path>m2repository</sdk:path>\n\ |
| 132 | <sdk:archives>\n\ |
Xavier Ducrohet | c16b62d | 2014-12-09 12:37:45 -0800 | [diff] [blame] | 133 | <sdk:archive>\n\ |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 134 | <sdk:size>${size}</sdk:size>\n\ |
| 135 | <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\ |
| 136 | <sdk:url>${repoArchiveName}</sdk:url>\n\ |
| 137 | </sdk:archive>\n\ |
| 138 | </sdk:archives>\n\ |
| 139 | </sdk:extra>\n\ |
| 140 | </sdk:sdk-addon>" |
| 141 | |
| 142 | Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8) |
| 143 | } |
| 144 | createArchive.dependsOn createXml |
| 145 | |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 146 | task(createSourceProp) << { |
| 147 | def sourceProp = |
| 148 | "Extra.VendorDisplay=Android\n\ |
| 149 | Extra.Path=m2repository\n\ |
| 150 | Archive.Arch=ANY\n\ |
| 151 | Extra.NameDisplay=Android Support Repository\n\ |
| 152 | Archive.Os=ANY\n\ |
Alan Viverette | 5ae24d6 | 2016-04-06 16:17:13 -0400 | [diff] [blame] | 153 | Pkg.Desc=Local Maven repository for Support Libraries\n\ |
Xavier Ducrohet | 64fe232 | 2014-06-16 17:59:34 -0700 | [diff] [blame] | 154 | Pkg.Revision=${project.ext.extraVersion}.0.0\n\ |
| 155 | Extra.VendorId=android" |
| 156 | |
| 157 | Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8) |
| 158 | } |
| 159 | createSourceProp.dependsOn unzipRepo |
| 160 | prepareRepo.dependsOn createSourceProp |
| 161 | |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 162 | import com.google.common.hash.HashCode |
| 163 | import com.google.common.hash.HashFunction |
| 164 | import com.google.common.hash.Hashing |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 165 | import java.nio.charset.Charset |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 166 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 167 | /** |
| 168 | * Generates SHA1 hash for the specified file's absolute path. |
| 169 | * |
| 170 | * @param inputFile file to hash |
| 171 | * @return SHA1 hash |
| 172 | */ |
| 173 | String getSha1(File inputFile) { |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 174 | HashFunction hashFunction = Hashing.sha1() |
Chris Banes | 96f1e91 | 2015-03-05 20:04:05 +0000 | [diff] [blame] | 175 | HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8")) |
Xavier Ducrohet | 9220b5b | 2014-03-21 15:30:01 -0700 | [diff] [blame] | 176 | return hashCode.toString() |
| 177 | } |
| 178 | |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 179 | /** |
| 180 | * Returns the Android prebuilt JAR for the specified API level. |
| 181 | * |
| 182 | * @param apiLevel the API level or "current" |
| 183 | * @return a file collection containing the Android prebuilt JAR |
| 184 | */ |
Yigit Boyar | 9673b85 | 2016-06-14 11:13:32 -0700 | [diff] [blame] | 185 | FileCollection getAndroidPrebuilt(apiLevel) { |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 186 | files("${project.rootDir}/../../prebuilts/sdk/$apiLevel/android.jar") |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 189 | void registerForDocsTask(Task task, Project subProject, releaseVariant) { |
| 190 | task.dependsOn releaseVariant.javaCompile |
| 191 | task.source { |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 192 | def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir) |
| 193 | return releaseVariant.javaCompile.source.minus(buildConfig) + |
| 194 | fileTree(releaseVariant.aidlCompile.sourceOutputDir) + |
| 195 | fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir) |
| 196 | } |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 197 | task.classpath += files(releaseVariant.javaCompile.classpath) + |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 198 | files(releaseVariant.javaCompile.destinationDir) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 201 | // Generates online docs. |
| 202 | task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 203 | docletpath = configurations.doclava.resolve() |
| 204 | destinationDir = new File(project.docsDir, "online") |
| 205 | |
| 206 | // Base classpath is Android SDK, sub-projects add their own. |
| 207 | classpath = getAndroidPrebuilt(gradle.ext.currentSdk) |
| 208 | |
| 209 | def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf') |
| 210 | hdfOption.add( |
| 211 | ['android.whichdoc', 'online'], |
| 212 | ['android.hasSamples', 'true']); |
| 213 | |
| 214 | options { |
| 215 | addStringOption "templatedir", |
| 216 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 217 | addStringOption "federate Android", "http://developer.android.com" |
| 218 | addStringOption "federationapi Android", |
| 219 | "${project.rootDir}/../../prebuilts/sdk/api/24.txt" |
| 220 | addStringOption "stubpackages", "android.support.*" |
| 221 | addStringOption "samplesdir", "${project.rootDir}/samples" |
| 222 | addOption hdfOption |
| 223 | } |
| 224 | |
| 225 | exclude '**/BuildConfig.java' |
| 226 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 227 | |
| 228 | // Generates API files. |
| 229 | task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) { |
| 230 | docletpath = configurations.doclava.resolve() |
| 231 | destinationDir = project.docsDir |
| 232 | |
| 233 | // Base classpath is Android SDK, sub-projects add their own. |
| 234 | classpath = getAndroidPrebuilt(gradle.ext.currentSdk) |
| 235 | |
| 236 | apiFile = new File(project.docsDir, 'release/current.txt') |
| 237 | removedApiFile = new File(project.docsDir, 'release/removed.txt') |
| 238 | generateDocs = false |
| 239 | |
| 240 | options { |
| 241 | addStringOption "templatedir", |
| 242 | "${project.rootDir}/../../build/tools/droiddoc/templates-sdk" |
| 243 | addStringOption "federate Android", "http://developer.android.com" |
| 244 | addStringOption "federationapi Android", |
| 245 | "${project.rootDir}/../../prebuilts/sdk/api/24.txt" |
| 246 | addStringOption "stubpackages", "android.support.*" |
| 247 | } |
| 248 | exclude '**/BuildConfig.java' |
| 249 | exclude '**/R.java' |
| 250 | } |
| 251 | |
| 252 | // Copies generated API files to current version. |
| 253 | task updateApi(type: UpdateApiTask, dependsOn: generateApi) { |
| 254 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 255 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 256 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 257 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Checks generated API files against current version. |
| 261 | task checkApi(type: CheckApiTask, dependsOn: generateApi) { |
| 262 | doclavaClasspath = generateApi.docletpath |
| 263 | |
| 264 | checkApiTaskPath = name |
| 265 | updateApiTaskPath = updateApi.name |
| 266 | |
| 267 | newApiFile = new File(project.docsDir, 'release/current.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 268 | oldApiFile = new File(project.rootDir, 'api/current.txt') |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 269 | newRemovedApiFile = new File(project.docsDir, 'release/removed.txt') |
Alan Viverette | 7b59d3a | 2016-06-13 12:52:20 -0400 | [diff] [blame] | 270 | oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt') |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 271 | } |
Alan Viverette | dd377c9 | 2016-06-24 09:51:49 -0400 | [diff] [blame] | 272 | createArchive.dependsOn checkApi |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 273 | |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 274 | subprojects { |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 275 | // Only modify android projects. |
| 276 | if (project.name.equals('doclava')) return; |
| 277 | |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 278 | // current SDK is set in studioCompat.gradle |
| 279 | project.ext.currentSdk = gradle.ext.currentSdk |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 280 | apply plugin: 'maven' |
Yigit Boyar | 3986e04 | 2016-02-08 18:31:38 -0800 | [diff] [blame] | 281 | |
Xavier Ducrohet | 855a922 | 2014-01-02 19:00:43 -0800 | [diff] [blame] | 282 | version = rootProject.ext.supportVersion |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 283 | group = 'com.android.support' |
| 284 | |
Yigit Boyar | be7a54a | 2015-04-07 13:23:50 -0700 | [diff] [blame] | 285 | repositories { |
| 286 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" } |
| 287 | maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" } |
| 288 | maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" } |
| 289 | } |
| 290 | |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 291 | project.plugins.whenPluginAdded { plugin -> |
Chris Banes | e17c519 | 2016-06-01 13:36:05 +0100 | [diff] [blame] | 292 | if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name) |
| 293 | || "com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 294 | project.android.buildToolsVersion = rootProject.buildToolsVersion |
Yigit Boyar | d8d42d5 | 2016-04-12 18:20:18 -0700 | [diff] [blame] | 295 | // enable code coverage for debug builds only if we are not running inside the IDE |
| 296 | // enabling coverage reports breaks the method parameter resolution in the IDE debugger |
| 297 | project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide') |
Alan Viverette | af6b251 | 2016-11-16 17:33:10 -0500 | [diff] [blame^] | 298 | |
| 299 | // Ensure we run API lint checks. |
| 300 | project.android.lintOptions.check 'NewApi' |
| 301 | project.android.lintOptions.fatal 'NewApi' |
| 302 | project.parent.lint.dependsOn project.lint |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 303 | } |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 304 | |
| 305 | // Create release and separate zip task for Android libraries (and android-annotations, |
| 306 | // which is just a Java library). |
| 307 | if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name) |
| 308 | || "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)) { |
| 309 | task release(type: Upload) { |
| 310 | configuration = configurations.archives |
| 311 | repositories { |
| 312 | mavenDeployer { |
| 313 | repository(url: uri("$rootProject.ext.supportRepoOut")) |
| 314 | |
| 315 | // Disable unique names for SNAPSHOTS so they can be updated in place. |
| 316 | setUniqueVersion(false) |
| 317 | doLast { |
| 318 | // Remove any invalid maven-metadata.xml files that may have been |
| 319 | // created for SNAPSHOT versions that are *not* uniquely versioned. |
| 320 | pom*.each { pom -> |
| 321 | if (pom.version.endsWith('-SNAPSHOT')) { |
| 322 | final File artifactDir = new File( |
| 323 | rootProject.ext.supportRepoOut, |
| 324 | pom.groupId.replace('.', '/') |
| 325 | + '/' + pom.artifactId |
| 326 | + '/' + pom.version) |
| 327 | delete fileTree(dir: artifactDir, |
| 328 | include: 'maven-metadata.xml*') |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | def deployer = release.repositories.mavenDeployer |
| 337 | deployer.pom*.whenConfigured { pom -> |
| 338 | pom.dependencies.findAll { dep -> |
| 339 | dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' |
| 340 | }*.type = 'aar' |
| 341 | } |
| 342 | |
| 343 | ext.versionDir = { |
| 344 | def groupDir = new File(rootProject.ext.supportRepoOut, |
| 345 | project.group.replace('.','/')) |
| 346 | def artifactDir = new File(groupDir, archivesBaseName) |
| 347 | return new File(artifactDir, version) |
| 348 | } |
| 349 | |
| 350 | task generateSourceProps(dependsOn: createRepository) << { |
| 351 | def content = "Maven.GroupId=$deployer.pom.groupId\n" + |
| 352 | "Maven.ArtifactId=$deployer.pom.artifactId\n" + |
| 353 | "Maven.Version=$deployer.pom.version\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 354 | "Extra.VendorDisplay=Android\n" + |
| 355 | "Extra.VendorId=android\n" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 356 | "Pkg.Desc=$project.name\n" + |
| 357 | "Pkg.Revision=1\n" + |
Alan Viverette | 4453f0d | 2016-09-14 12:32:27 -0700 | [diff] [blame] | 358 | "Maven.Dependencies=" + |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 359 | String.join(",", project.configurations.compile.allDependencies.collect { |
| 360 | def p = parent.findProject(it.name) |
| 361 | return p ? "$p.group:$p.archivesBaseName:$p.version" : null |
| 362 | }.grep()) + |
| 363 | "\n" |
| 364 | Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8) |
| 365 | } |
| 366 | |
| 367 | task createSeparateZip(type: Zip, dependsOn: generateSourceProps) { |
| 368 | into archivesBaseName |
| 369 | destinationDir project.parent.ext.distDir |
| 370 | baseName = project.group |
| 371 | version = project.parent.ext.buildNumber |
| 372 | } |
| 373 | project.parent.createArchive.dependsOn createSeparateZip |
| 374 | |
| 375 | // before the upload, make sure the repo is ready. |
| 376 | release.dependsOn rootProject.tasks.prepareRepo |
| 377 | // make the mainupload depend on this one. |
| 378 | mainUpload.dependsOn release |
| 379 | } |
Jeff Davidson | 84faec5 | 2014-06-18 09:10:36 -0700 | [diff] [blame] | 380 | } |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 381 | |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 382 | project.afterEvaluate { |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 383 | // The archivesBaseName isn't available intially, so set it now |
Alan Viverette | 573630e | 2016-07-08 17:17:47 -0400 | [diff] [blame] | 384 | def createZipTask = project.tasks.findByName("createSeparateZip") |
| 385 | if (createZipTask != null) { |
| 386 | createZipTask.appendix = archivesBaseName |
| 387 | createZipTask.from versionDir() |
| 388 | } |
Joe Baker-Malone | 5e2c51d | 2016-05-13 15:09:24 -0700 | [diff] [blame] | 389 | |
| 390 | // Copy instrumentation test APK into the dist dir |
Chris Banes | daea069 | 2015-12-29 12:48:24 +0000 | [diff] [blame] | 391 | def assembleTestTask = project.tasks.findByPath('assembleAndroidTest') |
| 392 | if (assembleTestTask != null) { |
| 393 | assembleTestTask.doLast { |
| 394 | // If the project actually has some instrumentation tests, copy its APK |
| 395 | if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) { |
| 396 | def pkgTask = project.tasks.findByPath('packageDebugAndroidTest') |
| 397 | copy { |
| 398 | from(pkgTask.outputFile) |
| 399 | into(rootProject.ext.testApkDistOut) |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
Yigit Boyar | ea5d9b2 | 2016-03-08 13:25:26 -0800 | [diff] [blame] | 405 | |
| 406 | project.afterEvaluate { p -> |
| 407 | // remove dependency on the test so that we still get coverage even if some tests fail |
| 408 | p.tasks.findAll { it instanceof JacocoReportTask}.each { task -> |
| 409 | def toBeRemoved = new ArrayList() |
| 410 | def dependencyList = task.taskDependencies.values |
| 411 | dependencyList.each { dep -> |
| 412 | if (dep instanceof String) { |
| 413 | def t = tasks.findByName(dep) |
| 414 | if (t instanceof DeviceProviderInstrumentTestTask) { |
| 415 | toBeRemoved.add(dep) |
| 416 | task.mustRunAfter(t) |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | toBeRemoved.each { dep -> |
| 421 | dependencyList.remove(dep) |
| 422 | } |
| 423 | } |
| 424 | } |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 425 | |
| 426 | project.afterEvaluate { p -> |
| 427 | if (p.hasProperty('android') |
| 428 | && p.android.hasProperty('libraryVariants') |
| 429 | && !(p.android.hasProperty('noDocs') && p.android.noDocs)) { |
| 430 | p.android.libraryVariants.all { v -> |
| 431 | if (v.name == 'release') { |
Alan Viverette | 9562a3b | 2016-07-01 13:26:39 -0400 | [diff] [blame] | 432 | registerForDocsTask(rootProject.generateDocs, p, v) |
| 433 | registerForDocsTask(rootProject.generateApi, p, v) |
Alan Viverette | cc5197e | 2016-06-13 12:45:07 -0400 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | } |
| 437 | } |
Xavier Ducrohet | 86fb8ef | 2013-02-22 15:04:37 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 440 | project.gradle.buildFinished { buildResult -> |
| 441 | if (buildResult.getFailure() != null) { |
| 442 | println() |
| 443 | println 'Build failed. Possible causes include:' |
| 444 | println ' 1) Bad codes' |
| 445 | println ' 2) Out of date prebuilts in prebuilts/sdk' |
Chris Banes | 9e2e803 | 2015-09-16 10:15:37 +0100 | [diff] [blame] | 446 | println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle' |
Chris Banes | 9ae4ee8 | 2015-09-11 10:32:15 +1000 | [diff] [blame] | 447 | println() |
| 448 | } |
| 449 | } |