blob: 41139295aebb45a53e4939915d2880b72097fde4 [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 Liutikasf8cf1452016-11-21 20:32:13 +000043gradle.ext.currentSdk = 25
Aurimas Liutikas232bf852016-12-12 10:33:31 -080044ext.supportVersion = '25.2.0-SNAPSHOT'
Kathy Kam09173382016-12-06 14:42:08 -080045ext.extraVersion = 41
Xavier Ducrohet020e4322014-03-18 16:41:30 -070046ext.supportRepoOut = ''
Aurimas Liutikas78449c12016-11-14 15:20:08 -080047ext.buildToolsVersion = '24.0.1'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080048ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080049
Aurimas Liutikasdfe75782016-08-03 14:27:20 -070050ext.testRunnerVersion = '0.6-alpha'
51ext.espressoVersion = '2.3-alpha'
52
Alan Viverettecc5197e2016-06-13 12:45:07 -040053// Enforce the use of prebuilt dependencies in all sub-projects. This is
54// required for the doclava dependency.
55ext.usePrebuilts = "true"
56
Aurimas Liutikasf8cf1452016-11-21 20:32:13 +000057// Use the embedded SDK by default, which can be overridden by setting the 'sdk.dir' property
58// (e.g. local.properties) or the 'ANDROID_HOME' environment variable.
59final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
Aurimas Liutikas3edb1fa2016-12-06 11:35:30 -080060ext.sdkDirectory = "${rootDir}/../../prebuilts/fullsdk-${platform}";
61System.setProperty('android.home', sdkDirectory)
Aurimas Liutikasf8cf1452016-11-21 20:32:13 +000062
Xavier Ducrohet020e4322014-03-18 16:41:30 -070063/*
64 * With the build server you are given two env variables.
65 * The OUT_DIR is a temporary directory you can use to put things during the build.
66 * The DIST_DIR is where you want to save things from the build.
67 *
68 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
69 */
70if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070071 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
72 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080073
74 // the build server does not pass the build number so we infer it from the last folder of the dist path.
75 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070076} else {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040077 buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build")
78 project.ext.distDir = file("${project.rootDir}/../../out/dist")
Xavier Ducrohet020e4322014-03-18 16:41:30 -070079}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080080
Alan Viverette9b5fe932016-07-22 10:28:31 -040081subprojects {
82 // Change buildDir first so that all plugins pick up the new value.
83 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
84}
85
Alan Viverettecc5197e2016-06-13 12:45:07 -040086ext.docsDir = new File(buildDir, 'javadoc')
Xavier Ducrohet020e4322014-03-18 16:41:30 -070087ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080088ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080089
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070090// Main task called by the build server.
91task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070092}
93
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070094// upload anchor for subprojects to upload their artifacts
95// to the local repo.
96task(mainUpload) << {
97}
98
99// repository creation task
100task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700101 from project.ext.supportRepoOut
102 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -0700103 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -0800104 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700105}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700106createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700107
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700108// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700109task unzipRepo(type: Copy) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400110 from "${project.rootDir}/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800111 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800112}
113
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700114unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700115 project.ext.supportRepoOut.deleteDir()
116 project.ext.supportRepoOut.mkdirs()
117}
118
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700119// anchor for prepare repo. This is post unzip + sourceProp.
120task(prepareRepo) << {
121}
122
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500123// lint every library
124task(lint) << {
125}
126
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700127task(createXml) << {
128 def repoArchive = createRepository.archivePath
129 def repoArchiveName = createRepository.archiveName
130 def size = repoArchive.length()
131 def sha1 = getSha1(repoArchive)
132
133 def xml =
134"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
135 <sdk:extra>\n\
136 <sdk:revision>\n\
137 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
138 </sdk:revision>\n\
139 <sdk:vendor-display>Android</sdk:vendor-display>\n\
140 <sdk:vendor-id>android</sdk:vendor-id>\n\
141 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
142 <sdk:path>m2repository</sdk:path>\n\
143 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -0800144 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700145 <sdk:size>${size}</sdk:size>\n\
146 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
147 <sdk:url>${repoArchiveName}</sdk:url>\n\
148 </sdk:archive>\n\
149 </sdk:archives>\n\
150 </sdk:extra>\n\
151</sdk:sdk-addon>"
152
153 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
154}
155createArchive.dependsOn createXml
156
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700157task(createSourceProp) << {
158 def sourceProp =
159"Extra.VendorDisplay=Android\n\
160Extra.Path=m2repository\n\
161Archive.Arch=ANY\n\
162Extra.NameDisplay=Android Support Repository\n\
163Archive.Os=ANY\n\
Alan Viverette5ae24d62016-04-06 16:17:13 -0400164Pkg.Desc=Local Maven repository for Support Libraries\n\
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700165Pkg.Revision=${project.ext.extraVersion}.0.0\n\
166Extra.VendorId=android"
167
168 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
169}
170createSourceProp.dependsOn unzipRepo
171prepareRepo.dependsOn createSourceProp
172
Chris Banes96f1e912015-03-05 20:04:05 +0000173import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700174
Alan Viverettecc5197e2016-06-13 12:45:07 -0400175/**
176 * Generates SHA1 hash for the specified file's absolute path.
177 *
178 * @param inputFile file to hash
179 * @return SHA1 hash
180 */
181String getSha1(File inputFile) {
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700182 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000183 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700184 return hashCode.toString()
185}
186
Alan Viverettecc5197e2016-06-13 12:45:07 -0400187/**
188 * Returns the Android prebuilt JAR for the specified API level.
189 *
190 * @param apiLevel the API level or "current"
191 * @return a file collection containing the Android prebuilt JAR
192 */
Yigit Boyar9673b852016-06-14 11:13:32 -0700193FileCollection getAndroidPrebuilt(apiLevel) {
Aurimas Liutikas3edb1fa2016-12-06 11:35:30 -0800194 files("${ext.sdkDirectory}/platforms/android-${apiLevel}/android.jar")
Alan Viverettecc5197e2016-06-13 12:45:07 -0400195}
196
Alan Viverette9562a3b2016-07-01 13:26:39 -0400197void registerForDocsTask(Task task, Project subProject, releaseVariant) {
198 task.dependsOn releaseVariant.javaCompile
199 task.source {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400200 def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir)
201 return releaseVariant.javaCompile.source.minus(buildConfig) +
202 fileTree(releaseVariant.aidlCompile.sourceOutputDir) +
203 fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir)
204 }
Alan Viverette9562a3b2016-07-01 13:26:39 -0400205 task.classpath += files(releaseVariant.javaCompile.classpath) +
Alan Viverettecc5197e2016-06-13 12:45:07 -0400206 files(releaseVariant.javaCompile.destinationDir)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400207}
208
Alan Viverette9562a3b2016-07-01 13:26:39 -0400209// Generates online docs.
210task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) {
211 docletpath = configurations.doclava.resolve()
212 destinationDir = new File(project.docsDir, "online")
213
214 // Base classpath is Android SDK, sub-projects add their own.
215 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
216
217 def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf')
218 hdfOption.add(
219 ['android.whichdoc', 'online'],
220 ['android.hasSamples', 'true']);
221
Alan Viverette989f27a2016-11-29 17:28:15 -0500222 // Default hidden errors + hidden superclass (111) and
223 // deprecation mismatch (113) to match framework docs.
224 final def hidden = [105, 107, 111, 112, 113, 115, 116, 121]
225
226 doclavaErrors = (101..122) - hidden
227 doclavaWarnings = []
228 doclavaHidden += hidden
229
Alan Viverette9562a3b2016-07-01 13:26:39 -0400230 options {
231 addStringOption "templatedir",
232 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
233 addStringOption "federate Android", "http://developer.android.com"
Alan Viverette9562a3b2016-07-01 13:26:39 -0400234 addStringOption "stubpackages", "android.support.*"
235 addStringOption "samplesdir", "${project.rootDir}/samples"
236 addOption hdfOption
237 }
238
239 exclude '**/BuildConfig.java'
240}
Alan Viverettecc5197e2016-06-13 12:45:07 -0400241
242// Generates API files.
243task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) {
244 docletpath = configurations.doclava.resolve()
245 destinationDir = project.docsDir
246
247 // Base classpath is Android SDK, sub-projects add their own.
248 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
249
250 apiFile = new File(project.docsDir, 'release/current.txt')
251 removedApiFile = new File(project.docsDir, 'release/removed.txt')
252 generateDocs = false
253
254 options {
255 addStringOption "templatedir",
256 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
257 addStringOption "federate Android", "http://developer.android.com"
Alan Viverettecc5197e2016-06-13 12:45:07 -0400258 addStringOption "stubpackages", "android.support.*"
259 }
260 exclude '**/BuildConfig.java'
261 exclude '**/R.java'
262}
263
264// Copies generated API files to current version.
265task updateApi(type: UpdateApiTask, dependsOn: generateApi) {
266 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400267 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400268 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400269 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400270}
271
272// Checks generated API files against current version.
273task checkApi(type: CheckApiTask, dependsOn: generateApi) {
274 doclavaClasspath = generateApi.docletpath
275
276 checkApiTaskPath = name
277 updateApiTaskPath = updateApi.name
278
Alan Viverette77d397d2016-11-23 13:14:16 -0500279 // Check that the API we're building hasn't changed from the development
280 // version. These typed of changes require an explicit API file update.
281 checkApiErrors = (2..30)-[22]
282 checkApiWarnings = []
283 checkApiHidden = [22]
284
Alan Viverettecc5197e2016-06-13 12:45:07 -0400285 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400286 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400287 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400288 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Yigit Boyar3986e042016-02-08 18:31:38 -0800289}
Alan Viverettedd377c92016-06-24 09:51:49 -0400290createArchive.dependsOn checkApi
Yigit Boyar3986e042016-02-08 18:31:38 -0800291
Alan Viverette77d397d2016-11-23 13:14:16 -0500292// Checks generated API files against current version.
293task checkApiStable(type: CheckApiTask, dependsOn: generateApi) {
294 doclavaClasspath = generateApi.docletpath
295
296 checkApiTaskPath = name
297 updateApiTaskPath = updateApi.name
298
299 // Check that the API we're building hasn't broken the last-released
300 // library version. These types of changes are forbidden.
301 checkApiErrors = (7..18)
302 checkApiWarnings = [23, 24]
303 checkApiHidden = (2..6) + (19..22) + (25..30)
304
305 def lastReleasedApiFile = null
306 def apiDir = new File(project.rootDir, 'api')
307 apiDir.eachFileMatch FileType.FILES, ~/(\d+\.){3}txt/, { File apiFile ->
308 if (lastReleasedApiFile == null || apiFile.name > lastReleasedApiFile.name) {
309 lastReleasedApiFile = apiFile;
310 }
311 }
312
313 newApiFile = new File(project.docsDir, 'release/current.txt')
314 oldApiFile = lastReleasedApiFile
315 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
316 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
317}
318checkApi.dependsOn checkApiStable
319
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800320subprojects {
Alan Viverette50323732016-12-02 11:18:03 -0500321 // Only modify Android projects.
Alan Viverettecc5197e2016-06-13 12:45:07 -0400322 if (project.name.equals('doclava')) return;
323
Alan Viverette50323732016-12-02 11:18:03 -0500324 // Current SDK is set in studioCompat.gradle.
Yigit Boyar3986e042016-02-08 18:31:38 -0800325 project.ext.currentSdk = gradle.ext.currentSdk
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800326 apply plugin: 'maven'
Yigit Boyar3986e042016-02-08 18:31:38 -0800327
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800328 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800329 group = 'com.android.support'
330
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700331 repositories {
332 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
333 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
334 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
335 }
336
Jeff Davidson84faec52014-06-18 09:10:36 -0700337 project.plugins.whenPluginAdded { plugin ->
Alan Viverette50323732016-12-02 11:18:03 -0500338 def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
339 def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
340 def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)
341
342 if (isAndroidLibrary || isAndroidApp) {
Jeff Davidson84faec52014-06-18 09:10:36 -0700343 project.android.buildToolsVersion = rootProject.buildToolsVersion
Alan Viverette50323732016-12-02 11:18:03 -0500344
345 // Enable code coverage for debug builds only if we are not running inside the IDE,
346 // since enabling coverage reports breaks the method parameter resolution in the IDE
347 // debugger.
Yigit Boyard8d42d52016-04-12 18:20:18 -0700348 project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500349
Alan Viverette50323732016-12-02 11:18:03 -0500350 // Enforce NewApi lint check as fatal.
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500351 project.android.lintOptions.check 'NewApi'
352 project.android.lintOptions.fatal 'NewApi'
353 project.parent.lint.dependsOn project.lint
Jeff Davidson84faec52014-06-18 09:10:36 -0700354 }
Alan Viverette573630e2016-07-08 17:17:47 -0400355
Alan Viverette50323732016-12-02 11:18:03 -0500356 if (isAndroidLibrary || isJavaLibrary) {
357 // Add library to the aggregate dependency report.
358 task allDeps(type: DependencyReportTask) {}
359
360 // Create release and separate zip task for library.
Alan Viverette573630e2016-07-08 17:17:47 -0400361 task release(type: Upload) {
362 configuration = configurations.archives
363 repositories {
364 mavenDeployer {
365 repository(url: uri("$rootProject.ext.supportRepoOut"))
366
367 // Disable unique names for SNAPSHOTS so they can be updated in place.
368 setUniqueVersion(false)
369 doLast {
370 // Remove any invalid maven-metadata.xml files that may have been
371 // created for SNAPSHOT versions that are *not* uniquely versioned.
372 pom*.each { pom ->
373 if (pom.version.endsWith('-SNAPSHOT')) {
374 final File artifactDir = new File(
375 rootProject.ext.supportRepoOut,
376 pom.groupId.replace('.', '/')
377 + '/' + pom.artifactId
378 + '/' + pom.version)
379 delete fileTree(dir: artifactDir,
380 include: 'maven-metadata.xml*')
381 }
382 }
383 }
384 }
385 }
386 }
387
388 def deployer = release.repositories.mavenDeployer
389 deployer.pom*.whenConfigured { pom ->
390 pom.dependencies.findAll { dep ->
391 dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations'
392 }*.type = 'aar'
393 }
394
395 ext.versionDir = {
396 def groupDir = new File(rootProject.ext.supportRepoOut,
397 project.group.replace('.','/'))
398 def artifactDir = new File(groupDir, archivesBaseName)
399 return new File(artifactDir, version)
400 }
401
402 task generateSourceProps(dependsOn: createRepository) << {
403 def content = "Maven.GroupId=$deployer.pom.groupId\n" +
404 "Maven.ArtifactId=$deployer.pom.artifactId\n" +
405 "Maven.Version=$deployer.pom.version\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700406 "Extra.VendorDisplay=Android\n" +
407 "Extra.VendorId=android\n" +
Alan Viverette573630e2016-07-08 17:17:47 -0400408 "Pkg.Desc=$project.name\n" +
409 "Pkg.Revision=1\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700410 "Maven.Dependencies=" +
Alan Viverette573630e2016-07-08 17:17:47 -0400411 String.join(",", project.configurations.compile.allDependencies.collect {
412 def p = parent.findProject(it.name)
413 return p ? "$p.group:$p.archivesBaseName:$p.version" : null
414 }.grep()) +
415 "\n"
416 Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8)
417 }
418
419 task createSeparateZip(type: Zip, dependsOn: generateSourceProps) {
420 into archivesBaseName
421 destinationDir project.parent.ext.distDir
422 baseName = project.group
423 version = project.parent.ext.buildNumber
424 }
425 project.parent.createArchive.dependsOn createSeparateZip
426
Alan Viverette50323732016-12-02 11:18:03 -0500427 // Before the upload, make sure the repo is ready.
Alan Viverette573630e2016-07-08 17:17:47 -0400428 release.dependsOn rootProject.tasks.prepareRepo
Alan Viverette50323732016-12-02 11:18:03 -0500429
430 // Make the mainupload depend on this one.
Alan Viverette573630e2016-07-08 17:17:47 -0400431 mainUpload.dependsOn release
432 }
Jeff Davidson84faec52014-06-18 09:10:36 -0700433 }
Chris Banesdaea0692015-12-29 12:48:24 +0000434
Chris Banesdaea0692015-12-29 12:48:24 +0000435 project.afterEvaluate {
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700436 // The archivesBaseName isn't available intially, so set it now
Alan Viverette573630e2016-07-08 17:17:47 -0400437 def createZipTask = project.tasks.findByName("createSeparateZip")
438 if (createZipTask != null) {
439 createZipTask.appendix = archivesBaseName
440 createZipTask.from versionDir()
441 }
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700442
443 // Copy instrumentation test APK into the dist dir
Chris Banesdaea0692015-12-29 12:48:24 +0000444 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
445 if (assembleTestTask != null) {
446 assembleTestTask.doLast {
447 // If the project actually has some instrumentation tests, copy its APK
448 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
449 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
450 copy {
451 from(pkgTask.outputFile)
452 into(rootProject.ext.testApkDistOut)
453 }
454 }
455 }
456 }
457 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800458
459 project.afterEvaluate { p ->
460 // remove dependency on the test so that we still get coverage even if some tests fail
461 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
462 def toBeRemoved = new ArrayList()
463 def dependencyList = task.taskDependencies.values
464 dependencyList.each { dep ->
465 if (dep instanceof String) {
466 def t = tasks.findByName(dep)
467 if (t instanceof DeviceProviderInstrumentTestTask) {
468 toBeRemoved.add(dep)
469 task.mustRunAfter(t)
470 }
471 }
472 }
473 toBeRemoved.each { dep ->
474 dependencyList.remove(dep)
475 }
476 }
477 }
Alan Viverettecc5197e2016-06-13 12:45:07 -0400478
479 project.afterEvaluate { p ->
480 if (p.hasProperty('android')
481 && p.android.hasProperty('libraryVariants')
482 && !(p.android.hasProperty('noDocs') && p.android.noDocs)) {
483 p.android.libraryVariants.all { v ->
484 if (v.name == 'release') {
Alan Viverette9562a3b2016-07-01 13:26:39 -0400485 registerForDocsTask(rootProject.generateDocs, p, v)
486 registerForDocsTask(rootProject.generateApi, p, v)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400487 }
488 }
489 }
490 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800491}
492
Chris Banes9ae4ee82015-09-11 10:32:15 +1000493project.gradle.buildFinished { buildResult ->
494 if (buildResult.getFailure() != null) {
495 println()
496 println 'Build failed. Possible causes include:'
497 println ' 1) Bad codes'
498 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100499 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000500 println()
501 }
502}