blob: e3417b3e48d5bb870742f7e8b21f98572c1a87e2 [file] [log] [blame]
Alan Viverette77d397d2016-11-23 13:14:16 -05001import android.support.checkapi.CheckApiTask
2import android.support.checkapi.UpdateApiTask
Alan Viverette9562a3b2016-07-01 13:26:39 -04003import android.support.doclava.DoclavaMultilineJavadocOptionFileOption
Alan Viverette77d397d2016-11-23 13:14:16 -05004import android.support.doclava.DoclavaTask
5
Yigit Boyarea5d9b22016-03-08 13:25:26 -08006import com.android.build.gradle.internal.coverage.JacocoReportTask
7import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
Aurimas Liutikasf8cf1452016-11-21 20:32:13 +00008import org.gradle.internal.os.OperatingSystem
Yigit Boyarea5d9b22016-03-08 13:25:26 -08009
Alan Viverette77d397d2016-11-23 13:14:16 -050010import com.google.common.base.Charsets
11import com.google.common.hash.HashCode
12import com.google.common.hash.HashFunction
13import com.google.common.hash.Hashing
14import com.google.common.io.Files
15
16import groovy.io.FileType
Alan Viverettecc5197e2016-06-13 12:45:07 -040017
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080018buildscript {
19 repositories {
20 maven { url '../../prebuilts/gradle-plugin' }
21 maven { url '../../prebuilts/tools/common/m2/repository' }
22 maven { url '../../prebuilts/tools/common/m2/internal' }
Yigit Boyarc9750a12016-01-06 17:28:55 -080023 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080024 }
25 dependencies {
Aurimas Liutikas5c6933b2016-09-20 09:55:40 -070026 // Keep gradle plugin version in sync with ub_supportlib-master manifest.
Aurimas Liutikas9135bd92016-12-16 10:53:43 -080027 classpath 'com.android.tools.build:gradle:2.2.4'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080028 }
29}
30
Alan Viverettecc5197e2016-06-13 12:45:07 -040031repositories {
32 maven { url '../../prebuilts/tools/common/m2/repository' }
33}
34
35configurations {
36 doclava
37}
38
39dependencies {
40 doclava project(':doclava')
41}
42
Aurimas Liutikas8c84cb42017-02-02 10:57:04 -080043ext.supportVersion = '25.4.0-SNAPSHOT'
Kathy Kam184df872017-03-07 12:07:18 -080044ext.extraVersion = 45
Xavier Ducrohet020e4322014-03-18 16:41:30 -070045ext.supportRepoOut = ''
Xavier Ducrohetfa385272014-11-14 13:12:09 -080046ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080047
Justin Klaassen7f96fc52017-02-13 08:52:18 -080048ext.buildToolsVersion = '25.0.0'
Aurimas Liutikasdfe75782016-08-03 14:27:20 -070049ext.testRunnerVersion = '0.6-alpha'
50ext.espressoVersion = '2.3-alpha'
51
Alan Viverettecc5197e2016-06-13 12:45:07 -040052// Enforce the use of prebuilt dependencies in all sub-projects. This is
53// required for the doclava dependency.
54ext.usePrebuilts = "true"
55
Justin Klaassen7f96fc52017-02-13 08:52:18 -080056// Prevent the Android Gradle plug-in from automatically downloading SDK dependencies.
57ext['android.builder.sdkDownload'] = false
58
Aurimas Liutikasf8cf1452016-11-21 20:32:13 +000059final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -080060System.setProperty('android.dir', "${rootDir}/../../")
61final String fullSdkPath = "${rootDir}/../../prebuilts/fullsdk-${platform}"
62if (file(fullSdkPath).exists()) {
63 gradle.ext.currentSdk = 25
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -080064 project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.ext.currentSdk}/android.jar")
65 System.setProperty('android.home', "${rootDir}/../../prebuilts/fullsdk-${platform}")
66 File props = file("local.properties")
67 props.write "sdk.dir=${fullSdkPath}"
68} else {
69 gradle.ext.currentSdk = 'current'
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -080070 project.ext.androidJar = files("${project.rootDir}/../../prebuilts/sdk/current/android.jar")
71 File props = file("local.properties")
72 props.write "android.dir=../../"
73}
Aurimas Liutikasf8cf1452016-11-21 20:32:13 +000074
Xavier Ducrohet020e4322014-03-18 16:41:30 -070075/*
76 * With the build server you are given two env variables.
77 * The OUT_DIR is a temporary directory you can use to put things during the build.
78 * The DIST_DIR is where you want to save things from the build.
79 *
80 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
81 */
82if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070083 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
84 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080085
86 // the build server does not pass the build number so we infer it from the last folder of the dist path.
87 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070088} else {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040089 buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build")
90 project.ext.distDir = file("${project.rootDir}/../../out/dist")
Xavier Ducrohet020e4322014-03-18 16:41:30 -070091}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080092
Alan Viverette9b5fe932016-07-22 10:28:31 -040093subprojects {
94 // Change buildDir first so that all plugins pick up the new value.
95 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
96}
97
Alan Viverettecc5197e2016-06-13 12:45:07 -040098ext.docsDir = new File(buildDir, 'javadoc')
Xavier Ducrohet020e4322014-03-18 16:41:30 -070099ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -0800100ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800101
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700102// Main task called by the build server.
103task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700104}
105
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700106// upload anchor for subprojects to upload their artifacts
107// to the local repo.
108task(mainUpload) << {
109}
110
111// repository creation task
112task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700113 from project.ext.supportRepoOut
114 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -0700115 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -0800116 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700117}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700118createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700119
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700120// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700121task unzipRepo(type: Copy) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400122 from "${project.rootDir}/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800123 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800124}
125
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700126unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700127 project.ext.supportRepoOut.deleteDir()
128 project.ext.supportRepoOut.mkdirs()
129}
130
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700131// anchor for prepare repo. This is post unzip + sourceProp.
132task(prepareRepo) << {
133}
134
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500135// lint every library
136task(lint) << {
137}
138
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700139task(createXml) << {
140 def repoArchive = createRepository.archivePath
141 def repoArchiveName = createRepository.archiveName
142 def size = repoArchive.length()
143 def sha1 = getSha1(repoArchive)
144
145 def xml =
146"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
147 <sdk:extra>\n\
148 <sdk:revision>\n\
149 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
150 </sdk:revision>\n\
151 <sdk:vendor-display>Android</sdk:vendor-display>\n\
152 <sdk:vendor-id>android</sdk:vendor-id>\n\
153 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
154 <sdk:path>m2repository</sdk:path>\n\
155 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -0800156 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700157 <sdk:size>${size}</sdk:size>\n\
158 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
159 <sdk:url>${repoArchiveName}</sdk:url>\n\
160 </sdk:archive>\n\
161 </sdk:archives>\n\
162 </sdk:extra>\n\
163</sdk:sdk-addon>"
164
165 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
166}
167createArchive.dependsOn createXml
Aurimas Liutikasfe67eb02017-01-27 11:04:44 -0800168createXml.dependsOn createRepository
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700169
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700170task(createSourceProp) << {
171 def sourceProp =
172"Extra.VendorDisplay=Android\n\
173Extra.Path=m2repository\n\
174Archive.Arch=ANY\n\
175Extra.NameDisplay=Android Support Repository\n\
176Archive.Os=ANY\n\
Alan Viverette5ae24d62016-04-06 16:17:13 -0400177Pkg.Desc=Local Maven repository for Support Libraries\n\
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700178Pkg.Revision=${project.ext.extraVersion}.0.0\n\
179Extra.VendorId=android"
180
181 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
182}
183createSourceProp.dependsOn unzipRepo
184prepareRepo.dependsOn createSourceProp
185
Chris Banes96f1e912015-03-05 20:04:05 +0000186import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700187
Alan Viverettecc5197e2016-06-13 12:45:07 -0400188/**
189 * Generates SHA1 hash for the specified file's absolute path.
190 *
191 * @param inputFile file to hash
192 * @return SHA1 hash
193 */
194String getSha1(File inputFile) {
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700195 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000196 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700197 return hashCode.toString()
198}
199
Alan Viverette9562a3b2016-07-01 13:26:39 -0400200void registerForDocsTask(Task task, Project subProject, releaseVariant) {
201 task.dependsOn releaseVariant.javaCompile
202 task.source {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400203 def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir)
204 return releaseVariant.javaCompile.source.minus(buildConfig) +
205 fileTree(releaseVariant.aidlCompile.sourceOutputDir) +
206 fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir)
207 }
Alan Viverette9562a3b2016-07-01 13:26:39 -0400208 task.classpath += files(releaseVariant.javaCompile.classpath) +
Alan Viverettecc5197e2016-06-13 12:45:07 -0400209 files(releaseVariant.javaCompile.destinationDir)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400210}
211
Alan Viverette9562a3b2016-07-01 13:26:39 -0400212// Generates online docs.
213task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) {
Aurimas Liutikas11670682017-02-14 23:21:54 -0800214 group = JavaBasePlugin.DOCUMENTATION_GROUP
215 description = 'Generates d.android.com style documentation.'
216
Alan Viverette9562a3b2016-07-01 13:26:39 -0400217 docletpath = configurations.doclava.resolve()
218 destinationDir = new File(project.docsDir, "online")
219
220 // Base classpath is Android SDK, sub-projects add their own.
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -0800221 classpath = project.ext.androidJar
Alan Viverette9562a3b2016-07-01 13:26:39 -0400222
223 def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf')
224 hdfOption.add(
225 ['android.whichdoc', 'online'],
226 ['android.hasSamples', 'true']);
227
Alan Viverette989f27a2016-11-29 17:28:15 -0500228 // Default hidden errors + hidden superclass (111) and
229 // deprecation mismatch (113) to match framework docs.
230 final def hidden = [105, 107, 111, 112, 113, 115, 116, 121]
231
232 doclavaErrors = (101..122) - hidden
233 doclavaWarnings = []
234 doclavaHidden += hidden
235
Alan Viverette9562a3b2016-07-01 13:26:39 -0400236 options {
237 addStringOption "templatedir",
238 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
Alan Viverette9562a3b2016-07-01 13:26:39 -0400239 addStringOption "stubpackages", "android.support.*"
240 addStringOption "samplesdir", "${project.rootDir}/samples"
241 addOption hdfOption
242 }
243
244 exclude '**/BuildConfig.java'
245}
Alan Viverettecc5197e2016-06-13 12:45:07 -0400246
247// Generates API files.
248task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) {
249 docletpath = configurations.doclava.resolve()
250 destinationDir = project.docsDir
251
252 // Base classpath is Android SDK, sub-projects add their own.
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -0800253 classpath = project.ext.androidJar
Alan Viverettecc5197e2016-06-13 12:45:07 -0400254
255 apiFile = new File(project.docsDir, 'release/current.txt')
256 removedApiFile = new File(project.docsDir, 'release/removed.txt')
257 generateDocs = false
258
259 options {
260 addStringOption "templatedir",
261 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
Alan Viverettecc5197e2016-06-13 12:45:07 -0400262 addStringOption "stubpackages", "android.support.*"
263 }
264 exclude '**/BuildConfig.java'
265 exclude '**/R.java'
266}
267
268// Copies generated API files to current version.
269task updateApi(type: UpdateApiTask, dependsOn: generateApi) {
Aurimas Liutikas11670682017-02-14 23:21:54 -0800270 group JavaBasePlugin.VERIFICATION_GROUP
271 description 'Invoke Doclava\'s ApiCheck tool to update current.txt based on current changes.'
272
Alan Viverettecc5197e2016-06-13 12:45:07 -0400273 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400274 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400275 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400276 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400277}
278
279// Checks generated API files against current version.
280task checkApi(type: CheckApiTask, dependsOn: generateApi) {
281 doclavaClasspath = generateApi.docletpath
282
283 checkApiTaskPath = name
284 updateApiTaskPath = updateApi.name
285
Alan Viverette77d397d2016-11-23 13:14:16 -0500286 // Check that the API we're building hasn't changed from the development
287 // version. These typed of changes require an explicit API file update.
288 checkApiErrors = (2..30)-[22]
289 checkApiWarnings = []
290 checkApiHidden = [22]
291
Alan Viverettecc5197e2016-06-13 12:45:07 -0400292 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400293 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400294 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400295 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Yigit Boyar3986e042016-02-08 18:31:38 -0800296}
Alan Viverettedd377c92016-06-24 09:51:49 -0400297createArchive.dependsOn checkApi
Yigit Boyar3986e042016-02-08 18:31:38 -0800298
Alan Viverette77d397d2016-11-23 13:14:16 -0500299// Checks generated API files against current version.
300task checkApiStable(type: CheckApiTask, dependsOn: generateApi) {
301 doclavaClasspath = generateApi.docletpath
302
303 checkApiTaskPath = name
304 updateApiTaskPath = updateApi.name
305
306 // Check that the API we're building hasn't broken the last-released
307 // library version. These types of changes are forbidden.
308 checkApiErrors = (7..18)
309 checkApiWarnings = [23, 24]
310 checkApiHidden = (2..6) + (19..22) + (25..30)
311
312 def lastReleasedApiFile = null
313 def apiDir = new File(project.rootDir, 'api')
314 apiDir.eachFileMatch FileType.FILES, ~/(\d+\.){3}txt/, { File apiFile ->
315 if (lastReleasedApiFile == null || apiFile.name > lastReleasedApiFile.name) {
316 lastReleasedApiFile = apiFile;
317 }
318 }
319
320 newApiFile = new File(project.docsDir, 'release/current.txt')
321 oldApiFile = lastReleasedApiFile
322 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
323 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
324}
325checkApi.dependsOn checkApiStable
326
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800327subprojects {
Alan Viverette50323732016-12-02 11:18:03 -0500328 // Only modify Android projects.
Alan Viverettecc5197e2016-06-13 12:45:07 -0400329 if (project.name.equals('doclava')) return;
330
Alan Viverette50323732016-12-02 11:18:03 -0500331 // Current SDK is set in studioCompat.gradle.
Yigit Boyar3986e042016-02-08 18:31:38 -0800332 project.ext.currentSdk = gradle.ext.currentSdk
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800333 apply plugin: 'maven'
Yigit Boyar3986e042016-02-08 18:31:38 -0800334
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800335 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800336 group = 'com.android.support'
337
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700338 repositories {
339 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
340 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
341 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
342 }
343
Jeff Davidson84faec52014-06-18 09:10:36 -0700344 project.plugins.whenPluginAdded { plugin ->
Alan Viverette50323732016-12-02 11:18:03 -0500345 def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
346 def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
347 def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)
348
349 if (isAndroidLibrary || isAndroidApp) {
Jeff Davidson84faec52014-06-18 09:10:36 -0700350 project.android.buildToolsVersion = rootProject.buildToolsVersion
Alan Viverette50323732016-12-02 11:18:03 -0500351
352 // Enable code coverage for debug builds only if we are not running inside the IDE,
353 // since enabling coverage reports breaks the method parameter resolution in the IDE
354 // debugger.
Yigit Boyard8d42d52016-04-12 18:20:18 -0700355 project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500356
Alan Viverette50323732016-12-02 11:18:03 -0500357 // Enforce NewApi lint check as fatal.
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500358 project.android.lintOptions.check 'NewApi'
359 project.android.lintOptions.fatal 'NewApi'
360 project.parent.lint.dependsOn project.lint
Jeff Davidson84faec52014-06-18 09:10:36 -0700361 }
Alan Viverette573630e2016-07-08 17:17:47 -0400362
Alan Viverette50323732016-12-02 11:18:03 -0500363 if (isAndroidLibrary || isJavaLibrary) {
364 // Add library to the aggregate dependency report.
365 task allDeps(type: DependencyReportTask) {}
366
367 // Create release and separate zip task for library.
Alan Viverette573630e2016-07-08 17:17:47 -0400368 task release(type: Upload) {
369 configuration = configurations.archives
370 repositories {
371 mavenDeployer {
372 repository(url: uri("$rootProject.ext.supportRepoOut"))
373
374 // Disable unique names for SNAPSHOTS so they can be updated in place.
375 setUniqueVersion(false)
376 doLast {
377 // Remove any invalid maven-metadata.xml files that may have been
378 // created for SNAPSHOT versions that are *not* uniquely versioned.
379 pom*.each { pom ->
380 if (pom.version.endsWith('-SNAPSHOT')) {
381 final File artifactDir = new File(
382 rootProject.ext.supportRepoOut,
383 pom.groupId.replace('.', '/')
384 + '/' + pom.artifactId
385 + '/' + pom.version)
386 delete fileTree(dir: artifactDir,
387 include: 'maven-metadata.xml*')
388 }
389 }
390 }
391 }
392 }
393 }
394
395 def deployer = release.repositories.mavenDeployer
396 deployer.pom*.whenConfigured { pom ->
397 pom.dependencies.findAll { dep ->
398 dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations'
399 }*.type = 'aar'
400 }
401
402 ext.versionDir = {
403 def groupDir = new File(rootProject.ext.supportRepoOut,
404 project.group.replace('.','/'))
405 def artifactDir = new File(groupDir, archivesBaseName)
406 return new File(artifactDir, version)
407 }
408
409 task generateSourceProps(dependsOn: createRepository) << {
410 def content = "Maven.GroupId=$deployer.pom.groupId\n" +
411 "Maven.ArtifactId=$deployer.pom.artifactId\n" +
412 "Maven.Version=$deployer.pom.version\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700413 "Extra.VendorDisplay=Android\n" +
414 "Extra.VendorId=android\n" +
Alan Viverette573630e2016-07-08 17:17:47 -0400415 "Pkg.Desc=$project.name\n" +
416 "Pkg.Revision=1\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700417 "Maven.Dependencies=" +
Alan Viverette573630e2016-07-08 17:17:47 -0400418 String.join(",", project.configurations.compile.allDependencies.collect {
419 def p = parent.findProject(it.name)
420 return p ? "$p.group:$p.archivesBaseName:$p.version" : null
421 }.grep()) +
422 "\n"
423 Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8)
424 }
425
426 task createSeparateZip(type: Zip, dependsOn: generateSourceProps) {
427 into archivesBaseName
428 destinationDir project.parent.ext.distDir
429 baseName = project.group
430 version = project.parent.ext.buildNumber
431 }
432 project.parent.createArchive.dependsOn createSeparateZip
433
Alan Viverette50323732016-12-02 11:18:03 -0500434 // Before the upload, make sure the repo is ready.
Alan Viverette573630e2016-07-08 17:17:47 -0400435 release.dependsOn rootProject.tasks.prepareRepo
Alan Viverette50323732016-12-02 11:18:03 -0500436
437 // Make the mainupload depend on this one.
Alan Viverette573630e2016-07-08 17:17:47 -0400438 mainUpload.dependsOn release
439 }
Jeff Davidson84faec52014-06-18 09:10:36 -0700440 }
Chris Banesdaea0692015-12-29 12:48:24 +0000441
Chris Banesdaea0692015-12-29 12:48:24 +0000442 project.afterEvaluate {
Aurimas Liutikas11670682017-02-14 23:21:54 -0800443 // The archivesBaseName isn't available initially, so set it now
Alan Viverette573630e2016-07-08 17:17:47 -0400444 def createZipTask = project.tasks.findByName("createSeparateZip")
445 if (createZipTask != null) {
446 createZipTask.appendix = archivesBaseName
447 createZipTask.from versionDir()
448 }
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700449
450 // Copy instrumentation test APK into the dist dir
Chris Banesdaea0692015-12-29 12:48:24 +0000451 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
452 if (assembleTestTask != null) {
453 assembleTestTask.doLast {
454 // If the project actually has some instrumentation tests, copy its APK
455 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
456 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
457 copy {
458 from(pkgTask.outputFile)
459 into(rootProject.ext.testApkDistOut)
460 }
461 }
462 }
463 }
464 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800465
466 project.afterEvaluate { p ->
467 // remove dependency on the test so that we still get coverage even if some tests fail
468 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
469 def toBeRemoved = new ArrayList()
470 def dependencyList = task.taskDependencies.values
471 dependencyList.each { dep ->
472 if (dep instanceof String) {
473 def t = tasks.findByName(dep)
474 if (t instanceof DeviceProviderInstrumentTestTask) {
475 toBeRemoved.add(dep)
476 task.mustRunAfter(t)
477 }
478 }
479 }
480 toBeRemoved.each { dep ->
481 dependencyList.remove(dep)
482 }
483 }
484 }
Alan Viverettecc5197e2016-06-13 12:45:07 -0400485
486 project.afterEvaluate { p ->
487 if (p.hasProperty('android')
488 && p.android.hasProperty('libraryVariants')
489 && !(p.android.hasProperty('noDocs') && p.android.noDocs)) {
490 p.android.libraryVariants.all { v ->
491 if (v.name == 'release') {
Alan Viverette9562a3b2016-07-01 13:26:39 -0400492 registerForDocsTask(rootProject.generateDocs, p, v)
493 registerForDocsTask(rootProject.generateApi, p, v)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400494 }
495 }
496 }
497 }
Alan Viverette8d912662017-01-05 14:25:25 -0500498
499 // Update the version meta-data in each Manifest
500 project.afterEvaluate { p ->
501 if (p.hasProperty('android')) {
502 p.android.defaultConfig.manifestPlaceholders =
503 ["support-version": rootProject.ext.supportVersion]
504 }
505 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800506}
507
Chris Banes9ae4ee82015-09-11 10:32:15 +1000508project.gradle.buildFinished { buildResult ->
509 if (buildResult.getFailure() != null) {
510 println()
511 println 'Build failed. Possible causes include:'
512 println ' 1) Bad codes'
513 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100514 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000515 println()
516 }
517}