blob: 650b6917c304ff3f75b2fedeacdae03d2b0d8863 [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
Kathy Kam184df872017-03-07 12:07:18 -080043ext.supportVersion = '25.3.0'
44ext.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"
239 addStringOption "federate Android", "http://developer.android.com"
Alan Viverette9562a3b2016-07-01 13:26:39 -0400240 addStringOption "stubpackages", "android.support.*"
241 addStringOption "samplesdir", "${project.rootDir}/samples"
242 addOption hdfOption
243 }
244
245 exclude '**/BuildConfig.java'
246}
Alan Viverettecc5197e2016-06-13 12:45:07 -0400247
248// Generates API files.
249task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) {
250 docletpath = configurations.doclava.resolve()
251 destinationDir = project.docsDir
252
253 // Base classpath is Android SDK, sub-projects add their own.
Aurimas Liutikas3146f0b2017-01-11 17:40:36 -0800254 classpath = project.ext.androidJar
Alan Viverettecc5197e2016-06-13 12:45:07 -0400255
256 apiFile = new File(project.docsDir, 'release/current.txt')
257 removedApiFile = new File(project.docsDir, 'release/removed.txt')
258 generateDocs = false
259
260 options {
261 addStringOption "templatedir",
262 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
263 addStringOption "federate Android", "http://developer.android.com"
Alan Viverettecc5197e2016-06-13 12:45:07 -0400264 addStringOption "stubpackages", "android.support.*"
265 }
266 exclude '**/BuildConfig.java'
267 exclude '**/R.java'
268}
269
270// Copies generated API files to current version.
271task updateApi(type: UpdateApiTask, dependsOn: generateApi) {
Aurimas Liutikas11670682017-02-14 23:21:54 -0800272 group JavaBasePlugin.VERIFICATION_GROUP
273 description 'Invoke Doclava\'s ApiCheck tool to update current.txt based on current changes.'
274
Alan Viverettecc5197e2016-06-13 12:45:07 -0400275 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400276 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400277 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400278 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400279}
280
281// Checks generated API files against current version.
282task checkApi(type: CheckApiTask, dependsOn: generateApi) {
283 doclavaClasspath = generateApi.docletpath
284
285 checkApiTaskPath = name
286 updateApiTaskPath = updateApi.name
287
Alan Viverette77d397d2016-11-23 13:14:16 -0500288 // Check that the API we're building hasn't changed from the development
289 // version. These typed of changes require an explicit API file update.
290 checkApiErrors = (2..30)-[22]
291 checkApiWarnings = []
292 checkApiHidden = [22]
293
Alan Viverettecc5197e2016-06-13 12:45:07 -0400294 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400295 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400296 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400297 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Yigit Boyar3986e042016-02-08 18:31:38 -0800298}
Alan Viverettedd377c92016-06-24 09:51:49 -0400299createArchive.dependsOn checkApi
Yigit Boyar3986e042016-02-08 18:31:38 -0800300
Alan Viverette77d397d2016-11-23 13:14:16 -0500301// Checks generated API files against current version.
302task checkApiStable(type: CheckApiTask, dependsOn: generateApi) {
303 doclavaClasspath = generateApi.docletpath
304
305 checkApiTaskPath = name
306 updateApiTaskPath = updateApi.name
307
308 // Check that the API we're building hasn't broken the last-released
309 // library version. These types of changes are forbidden.
310 checkApiErrors = (7..18)
311 checkApiWarnings = [23, 24]
312 checkApiHidden = (2..6) + (19..22) + (25..30)
313
314 def lastReleasedApiFile = null
315 def apiDir = new File(project.rootDir, 'api')
316 apiDir.eachFileMatch FileType.FILES, ~/(\d+\.){3}txt/, { File apiFile ->
317 if (lastReleasedApiFile == null || apiFile.name > lastReleasedApiFile.name) {
318 lastReleasedApiFile = apiFile;
319 }
320 }
321
322 newApiFile = new File(project.docsDir, 'release/current.txt')
323 oldApiFile = lastReleasedApiFile
324 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
325 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
326}
327checkApi.dependsOn checkApiStable
328
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800329subprojects {
Alan Viverette50323732016-12-02 11:18:03 -0500330 // Only modify Android projects.
Alan Viverettecc5197e2016-06-13 12:45:07 -0400331 if (project.name.equals('doclava')) return;
332
Alan Viverette50323732016-12-02 11:18:03 -0500333 // Current SDK is set in studioCompat.gradle.
Yigit Boyar3986e042016-02-08 18:31:38 -0800334 project.ext.currentSdk = gradle.ext.currentSdk
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800335 apply plugin: 'maven'
Yigit Boyar3986e042016-02-08 18:31:38 -0800336
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800337 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800338 group = 'com.android.support'
339
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700340 repositories {
341 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
342 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
343 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
344 }
345
Jeff Davidson84faec52014-06-18 09:10:36 -0700346 project.plugins.whenPluginAdded { plugin ->
Alan Viverette50323732016-12-02 11:18:03 -0500347 def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
348 def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
349 def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)
350
351 if (isAndroidLibrary || isAndroidApp) {
Jeff Davidson84faec52014-06-18 09:10:36 -0700352 project.android.buildToolsVersion = rootProject.buildToolsVersion
Alan Viverette50323732016-12-02 11:18:03 -0500353
354 // Enable code coverage for debug builds only if we are not running inside the IDE,
355 // since enabling coverage reports breaks the method parameter resolution in the IDE
356 // debugger.
Yigit Boyard8d42d52016-04-12 18:20:18 -0700357 project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500358
Alan Viverette50323732016-12-02 11:18:03 -0500359 // Enforce NewApi lint check as fatal.
Alan Viveretteaf6b2512016-11-16 17:33:10 -0500360 project.android.lintOptions.check 'NewApi'
361 project.android.lintOptions.fatal 'NewApi'
362 project.parent.lint.dependsOn project.lint
Jeff Davidson84faec52014-06-18 09:10:36 -0700363 }
Alan Viverette573630e2016-07-08 17:17:47 -0400364
Alan Viverette50323732016-12-02 11:18:03 -0500365 if (isAndroidLibrary || isJavaLibrary) {
366 // Add library to the aggregate dependency report.
367 task allDeps(type: DependencyReportTask) {}
368
369 // Create release and separate zip task for library.
Alan Viverette573630e2016-07-08 17:17:47 -0400370 task release(type: Upload) {
371 configuration = configurations.archives
372 repositories {
373 mavenDeployer {
374 repository(url: uri("$rootProject.ext.supportRepoOut"))
375
376 // Disable unique names for SNAPSHOTS so they can be updated in place.
377 setUniqueVersion(false)
378 doLast {
379 // Remove any invalid maven-metadata.xml files that may have been
380 // created for SNAPSHOT versions that are *not* uniquely versioned.
381 pom*.each { pom ->
382 if (pom.version.endsWith('-SNAPSHOT')) {
383 final File artifactDir = new File(
384 rootProject.ext.supportRepoOut,
385 pom.groupId.replace('.', '/')
386 + '/' + pom.artifactId
387 + '/' + pom.version)
388 delete fileTree(dir: artifactDir,
389 include: 'maven-metadata.xml*')
390 }
391 }
392 }
393 }
394 }
395 }
396
397 def deployer = release.repositories.mavenDeployer
398 deployer.pom*.whenConfigured { pom ->
399 pom.dependencies.findAll { dep ->
400 dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations'
401 }*.type = 'aar'
402 }
403
404 ext.versionDir = {
405 def groupDir = new File(rootProject.ext.supportRepoOut,
406 project.group.replace('.','/'))
407 def artifactDir = new File(groupDir, archivesBaseName)
408 return new File(artifactDir, version)
409 }
410
411 task generateSourceProps(dependsOn: createRepository) << {
412 def content = "Maven.GroupId=$deployer.pom.groupId\n" +
413 "Maven.ArtifactId=$deployer.pom.artifactId\n" +
414 "Maven.Version=$deployer.pom.version\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700415 "Extra.VendorDisplay=Android\n" +
416 "Extra.VendorId=android\n" +
Alan Viverette573630e2016-07-08 17:17:47 -0400417 "Pkg.Desc=$project.name\n" +
418 "Pkg.Revision=1\n" +
Alan Viverette4453f0d2016-09-14 12:32:27 -0700419 "Maven.Dependencies=" +
Alan Viverette573630e2016-07-08 17:17:47 -0400420 String.join(",", project.configurations.compile.allDependencies.collect {
421 def p = parent.findProject(it.name)
422 return p ? "$p.group:$p.archivesBaseName:$p.version" : null
423 }.grep()) +
424 "\n"
425 Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8)
426 }
427
428 task createSeparateZip(type: Zip, dependsOn: generateSourceProps) {
429 into archivesBaseName
430 destinationDir project.parent.ext.distDir
431 baseName = project.group
432 version = project.parent.ext.buildNumber
433 }
434 project.parent.createArchive.dependsOn createSeparateZip
435
Alan Viverette50323732016-12-02 11:18:03 -0500436 // Before the upload, make sure the repo is ready.
Alan Viverette573630e2016-07-08 17:17:47 -0400437 release.dependsOn rootProject.tasks.prepareRepo
Alan Viverette50323732016-12-02 11:18:03 -0500438
439 // Make the mainupload depend on this one.
Alan Viverette573630e2016-07-08 17:17:47 -0400440 mainUpload.dependsOn release
441 }
Jeff Davidson84faec52014-06-18 09:10:36 -0700442 }
Chris Banesdaea0692015-12-29 12:48:24 +0000443
Chris Banesdaea0692015-12-29 12:48:24 +0000444 project.afterEvaluate {
Aurimas Liutikas11670682017-02-14 23:21:54 -0800445 // The archivesBaseName isn't available initially, so set it now
Alan Viverette573630e2016-07-08 17:17:47 -0400446 def createZipTask = project.tasks.findByName("createSeparateZip")
447 if (createZipTask != null) {
448 createZipTask.appendix = archivesBaseName
449 createZipTask.from versionDir()
450 }
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700451
452 // Copy instrumentation test APK into the dist dir
Chris Banesdaea0692015-12-29 12:48:24 +0000453 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
454 if (assembleTestTask != null) {
455 assembleTestTask.doLast {
456 // If the project actually has some instrumentation tests, copy its APK
457 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
458 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
459 copy {
460 from(pkgTask.outputFile)
461 into(rootProject.ext.testApkDistOut)
462 }
463 }
464 }
465 }
466 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800467
468 project.afterEvaluate { p ->
469 // remove dependency on the test so that we still get coverage even if some tests fail
470 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
471 def toBeRemoved = new ArrayList()
472 def dependencyList = task.taskDependencies.values
473 dependencyList.each { dep ->
474 if (dep instanceof String) {
475 def t = tasks.findByName(dep)
476 if (t instanceof DeviceProviderInstrumentTestTask) {
477 toBeRemoved.add(dep)
478 task.mustRunAfter(t)
479 }
480 }
481 }
482 toBeRemoved.each { dep ->
483 dependencyList.remove(dep)
484 }
485 }
486 }
Alan Viverettecc5197e2016-06-13 12:45:07 -0400487
488 project.afterEvaluate { p ->
489 if (p.hasProperty('android')
490 && p.android.hasProperty('libraryVariants')
491 && !(p.android.hasProperty('noDocs') && p.android.noDocs)) {
492 p.android.libraryVariants.all { v ->
493 if (v.name == 'release') {
Alan Viverette9562a3b2016-07-01 13:26:39 -0400494 registerForDocsTask(rootProject.generateDocs, p, v)
495 registerForDocsTask(rootProject.generateApi, p, v)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400496 }
497 }
498 }
499 }
Alan Viverette8d912662017-01-05 14:25:25 -0500500
501 // Update the version meta-data in each Manifest
502 project.afterEvaluate { p ->
503 if (p.hasProperty('android')) {
504 p.android.defaultConfig.manifestPlaceholders =
505 ["support-version": rootProject.ext.supportVersion]
506 }
507 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800508}
509
Chris Banes9ae4ee82015-09-11 10:32:15 +1000510project.gradle.buildFinished { buildResult ->
511 if (buildResult.getFailure() != null) {
512 println()
513 println 'Build failed. Possible causes include:'
514 println ' 1) Bad codes'
515 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100516 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000517 println()
518 }
519}