blob: 8768f567e61fd1deaa4cc0f77a628e3fd3efe2d9 [file] [log] [blame]
Alan Viverette9562a3b2016-07-01 13:26:39 -04001import android.support.doclava.DoclavaMultilineJavadocOptionFileOption
Yigit Boyarea5d9b22016-03-08 13:25:26 -08002import com.android.build.gradle.internal.coverage.JacocoReportTask
3import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
4
Alan Viverettecc5197e2016-06-13 12:45:07 -04005import android.support.checkapi.CheckApiTask
6import android.support.checkapi.UpdateApiTask
7import android.support.doclava.DoclavaTask
8
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08009buildscript {
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 Boyarc9750a12016-01-06 17:28:55 -080014 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080015 }
16 dependencies {
Yigit Boyar34602702016-08-23 11:27:58 -070017 classpath 'com.android.tools.build:gradle:2.2.0-beta2'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080018 }
19}
20
Alan Viverettecc5197e2016-06-13 12:45:07 -040021repositories {
22 maven { url '../../prebuilts/tools/common/m2/repository' }
23}
24
25configurations {
26 doclava
27}
28
29dependencies {
30 doclava project(':doclava')
31}
32
Chris Flatt10176842016-06-09 08:29:48 -070033ext.supportVersion = '25.0.0-SNAPSHOT'
Alan Viverette951bd072016-07-13 15:33:36 -040034ext.extraVersion = 36
Xavier Ducrohet020e4322014-03-18 16:41:30 -070035ext.supportRepoOut = ''
Yigit Boyarc9750a12016-01-06 17:28:55 -080036ext.buildToolsVersion = '23.0.2'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080037ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080038
Aurimas Liutikasdfe75782016-08-03 14:27:20 -070039ext.testRunnerVersion = '0.6-alpha'
40ext.espressoVersion = '2.3-alpha'
41
Alan Viverettecc5197e2016-06-13 12:45:07 -040042// Enforce the use of prebuilt dependencies in all sub-projects. This is
43// required for the doclava dependency.
44ext.usePrebuilts = "true"
45
Xavier Ducrohet020e4322014-03-18 16:41:30 -070046/*
47 * With the build server you are given two env variables.
48 * The OUT_DIR is a temporary directory you can use to put things during the build.
49 * The DIST_DIR is where you want to save things from the build.
50 *
51 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
52 */
53if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070054 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
55 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080056
57 // the build server does not pass the build number so we infer it from the last folder of the dist path.
58 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070059} else {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040060 buildDir = file("${project.rootDir}/../../out/host/gradle/frameworks/support/build")
61 project.ext.distDir = file("${project.rootDir}/../../out/dist")
Xavier Ducrohet020e4322014-03-18 16:41:30 -070062}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080063
Alan Viverette9b5fe932016-07-22 10:28:31 -040064subprojects {
65 // Change buildDir first so that all plugins pick up the new value.
66 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
67}
68
Alan Viverettecc5197e2016-06-13 12:45:07 -040069ext.docsDir = new File(buildDir, 'javadoc')
Xavier Ducrohet020e4322014-03-18 16:41:30 -070070ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080071ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080072
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070073// Main task called by the build server.
74task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070075}
76
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070077// upload anchor for subprojects to upload their artifacts
78// to the local repo.
79task(mainUpload) << {
80}
81
82// repository creation task
83task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070084 from project.ext.supportRepoOut
85 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070086 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080087 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070088}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070089createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070090
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070091// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070092task unzipRepo(type: Copy) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -040093 from "${project.rootDir}/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080094 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080095}
96
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070097unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070098 project.ext.supportRepoOut.deleteDir()
99 project.ext.supportRepoOut.mkdirs()
100}
101
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700102// anchor for prepare repo. This is post unzip + sourceProp.
103task(prepareRepo) << {
104}
105
Yigit Boyar3986e042016-02-08 18:31:38 -0800106
107import android.support.build.ApiModule
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700108import com.google.common.io.Files
109import com.google.common.base.Charsets
110
111task(createXml) << {
112 def repoArchive = createRepository.archivePath
113 def repoArchiveName = createRepository.archiveName
114 def size = repoArchive.length()
115 def sha1 = getSha1(repoArchive)
116
117 def xml =
118"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
119 <sdk:extra>\n\
120 <sdk:revision>\n\
121 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
122 </sdk:revision>\n\
123 <sdk:vendor-display>Android</sdk:vendor-display>\n\
124 <sdk:vendor-id>android</sdk:vendor-id>\n\
125 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
126 <sdk:path>m2repository</sdk:path>\n\
127 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -0800128 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700129 <sdk:size>${size}</sdk:size>\n\
130 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
131 <sdk:url>${repoArchiveName}</sdk:url>\n\
132 </sdk:archive>\n\
133 </sdk:archives>\n\
134 </sdk:extra>\n\
135</sdk:sdk-addon>"
136
137 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
138}
139createArchive.dependsOn createXml
140
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700141task(createSourceProp) << {
142 def sourceProp =
143"Extra.VendorDisplay=Android\n\
144Extra.Path=m2repository\n\
145Archive.Arch=ANY\n\
146Extra.NameDisplay=Android Support Repository\n\
147Archive.Os=ANY\n\
Alan Viverette5ae24d62016-04-06 16:17:13 -0400148Pkg.Desc=Local Maven repository for Support Libraries\n\
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700149Pkg.Revision=${project.ext.extraVersion}.0.0\n\
150Extra.VendorId=android"
151
152 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
153}
154createSourceProp.dependsOn unzipRepo
155prepareRepo.dependsOn createSourceProp
156
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700157import com.google.common.hash.HashCode
158import com.google.common.hash.HashFunction
159import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000160import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700161
Alan Viverettecc5197e2016-06-13 12:45:07 -0400162/**
163 * Generates SHA1 hash for the specified file's absolute path.
164 *
165 * @param inputFile file to hash
166 * @return SHA1 hash
167 */
168String getSha1(File inputFile) {
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700169 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000170 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700171 return hashCode.toString()
172}
173
Alan Viverettecc5197e2016-06-13 12:45:07 -0400174/**
175 * Returns the Android prebuilt JAR for the specified API level.
176 *
177 * @param apiLevel the API level or "current"
178 * @return a file collection containing the Android prebuilt JAR
179 */
Yigit Boyar9673b852016-06-14 11:13:32 -0700180FileCollection getAndroidPrebuilt(apiLevel) {
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400181 files("${project.rootDir}/../../prebuilts/sdk/$apiLevel/android.jar")
Alan Viverettecc5197e2016-06-13 12:45:07 -0400182}
183
184/**
185 * Populates the sub-project's set of source sets with the specified modules.
186 *
187 * @param subProject the sub-project to which the modules belong
188 * @param apiModules the modules from which to populate
189 */
190void createApiSourceSets(Project subProject, List<ApiModule> apiModules) {
Yigit Boyar3986e042016-02-08 18:31:38 -0800191 subProject.ext._apiModules = apiModules
192 subProject.ext.allSS = []
193 if (gradle.ext.studioCompat.enableApiModules) {
194 // nothing to do, they are all modules
195 return
196 }
197 // create a jar task for the api specific internal implementations
198 def internalJar = subProject.tasks.create(name: "internalJar", type: Jar) {
199 baseName "internal_impl"
200 }
201 apiModules.each { ApiModule apiModule ->
202 apiModule.sourceSet = createApiSourceset(subProject, apiModule.folderName, apiModule.folderName,
203 apiModule.apiForSourceSet.toString(), apiModule.prev == null ? null : apiModule.prev.sourceSet)
204 subProject.ext.allSS.add(apiModule.sourceSet)
205 }
206 subProject.android.libraryVariants.all { variant ->
207 variant.javaCompile.dependsOn internalJar
208 }
209}
210
Alan Viverettecc5197e2016-06-13 12:45:07 -0400211/**
212 * Adds the specified module to the sub-project's set of source sets and
213 * internal JAR. Also sets up dependencies, if supplied.
214 *
215 * @param subProject the sub-project to which the module belongs
216 * @param name the name of the module
217 * @param folder the module's source folder
218 * @param apiLevel the module's compile API level
219 * @param previousSource source set dependency (optional)
220 * @return a source set for the module
221 */
222SourceSet createApiSourceset(Project subProject, String name, String folder, String apiLevel,
Yigit Boyar3986e042016-02-08 18:31:38 -0800223 SourceSet previousSource) {
224 def sourceSet = subProject.sourceSets.create(name)
225 sourceSet.java.srcDirs = [folder]
226
Alan Viverettea93997e2016-07-15 12:42:45 -0400227 // The Android gradle plugin doesn't touch Java sub-tasks, so we need to
228 // manually set the Java task's boot classpath to the correct Android SDK.
229 def compileJavaTaskName = sourceSet.getCompileJavaTaskName();
230 def compileJavaOptions = subProject.tasks."${compileJavaTaskName}".options
231 compileJavaOptions.bootClasspath = getAndroidPrebuilt(apiLevel)
Yigit Boyar3986e042016-02-08 18:31:38 -0800232
Alan Viverettea93997e2016-07-15 12:42:45 -0400233 // Useful for cleaning up compiler warnings...
234 //compileJavaOptions.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
235
236 def configName = sourceSet.getCompileConfigurationName()
Yigit Boyar3986e042016-02-08 18:31:38 -0800237 subProject.getDependencies().add(configName, getAndroidPrebuilt(apiLevel))
238 if (previousSource != null) {
239 setupDependencies(subProject, configName, previousSource)
240 }
241 subProject.ext.allSS.add(sourceSet)
242 subProject.tasks.internalJar.from sourceSet.output
243 return sourceSet
244}
245
Alan Viverettecc5197e2016-06-13 12:45:07 -0400246/**
247 * Adds the specified source set as a dependency for the sub-project.
248 *
249 * @param subProject the sub-project to modify
250 * @param configName
251 * @param previousSourceSet the source set to add as a dependency
252 */
253void setupDependencies(Project subProject, String configName, SourceSet previousSourceSet) {
254 subProject.getDependencies().add(configName, previousSourceSet.output)
255 subProject.getDependencies().add(configName, previousSourceSet.compileClasspath)
256}
257
258void setApiModuleDependencies(Project subProject, DependencyHandler handler, List extraDeps) {
Yigit Boyar3986e042016-02-08 18:31:38 -0800259 if (gradle.ext.studioCompat.enableApiModules) {
260 subProject.android.enforceUniquePackageName=false
261 // add dependency on the latest module
262 handler.compile(project(subProject.ext._apiModules.last().moduleName))
263 } else {
264 handler.compile(files(subProject.tasks.internalJar.archivePath))
265 def firstModule = subProject.ext._apiModules[0]
266 extraDeps.each { dep ->
267 handler."${firstModule.folderName}Compile"(project(dep))
268 handler.compile(project(dep))
269 }
Yigit Boyar3986e042016-02-08 18:31:38 -0800270 }
271}
272
Alan Viverette9562a3b2016-07-01 13:26:39 -0400273void registerForDocsTask(Task task, Project subProject, releaseVariant) {
274 task.dependsOn releaseVariant.javaCompile
275 task.source {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400276 def buildConfig = fileTree(releaseVariant.getGenerateBuildConfig().sourceOutputDir)
277 return releaseVariant.javaCompile.source.minus(buildConfig) +
278 fileTree(releaseVariant.aidlCompile.sourceOutputDir) +
279 fileTree(releaseVariant.outputs[0].processResources.sourceOutputDir)
280 }
Alan Viverette9562a3b2016-07-01 13:26:39 -0400281 task.classpath += files(releaseVariant.javaCompile.classpath) +
Alan Viverettecc5197e2016-06-13 12:45:07 -0400282 files(releaseVariant.javaCompile.destinationDir)
283
284 if (subProject.hasProperty('allSS')) {
285 subProject.allSS.each { ss ->
Alan Viverette9562a3b2016-07-01 13:26:39 -0400286 task.source ss.java
Alan Viverettecc5197e2016-06-13 12:45:07 -0400287 }
288 }
289}
290
Alan Viverette9562a3b2016-07-01 13:26:39 -0400291// Generates online docs.
292task generateDocs(type: DoclavaTask, dependsOn: configurations.doclava) {
293 docletpath = configurations.doclava.resolve()
294 destinationDir = new File(project.docsDir, "online")
295
296 // Base classpath is Android SDK, sub-projects add their own.
297 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
298
299 def hdfOption = new DoclavaMultilineJavadocOptionFileOption('hdf')
300 hdfOption.add(
301 ['android.whichdoc', 'online'],
302 ['android.hasSamples', 'true']);
303
304 options {
305 addStringOption "templatedir",
306 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
307 addStringOption "federate Android", "http://developer.android.com"
308 addStringOption "federationapi Android",
309 "${project.rootDir}/../../prebuilts/sdk/api/24.txt"
310 addStringOption "stubpackages", "android.support.*"
311 addStringOption "samplesdir", "${project.rootDir}/samples"
312 addOption hdfOption
313 }
314
315 exclude '**/BuildConfig.java'
316}
Alan Viverettecc5197e2016-06-13 12:45:07 -0400317
318// Generates API files.
319task generateApi(type: DoclavaTask, dependsOn: configurations.doclava) {
320 docletpath = configurations.doclava.resolve()
321 destinationDir = project.docsDir
322
323 // Base classpath is Android SDK, sub-projects add their own.
324 classpath = getAndroidPrebuilt(gradle.ext.currentSdk)
325
326 apiFile = new File(project.docsDir, 'release/current.txt')
327 removedApiFile = new File(project.docsDir, 'release/removed.txt')
328 generateDocs = false
329
330 options {
331 addStringOption "templatedir",
332 "${project.rootDir}/../../build/tools/droiddoc/templates-sdk"
333 addStringOption "federate Android", "http://developer.android.com"
334 addStringOption "federationapi Android",
335 "${project.rootDir}/../../prebuilts/sdk/api/24.txt"
336 addStringOption "stubpackages", "android.support.*"
337 }
338 exclude '**/BuildConfig.java'
339 exclude '**/R.java'
340}
341
342// Copies generated API files to current version.
343task updateApi(type: UpdateApiTask, dependsOn: generateApi) {
344 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400345 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400346 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400347 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400348}
349
350// Checks generated API files against current version.
351task checkApi(type: CheckApiTask, dependsOn: generateApi) {
352 doclavaClasspath = generateApi.docletpath
353
354 checkApiTaskPath = name
355 updateApiTaskPath = updateApi.name
356
357 newApiFile = new File(project.docsDir, 'release/current.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400358 oldApiFile = new File(project.rootDir, 'api/current.txt')
Alan Viverettecc5197e2016-06-13 12:45:07 -0400359 newRemovedApiFile = new File(project.docsDir, 'release/removed.txt')
Alan Viverette7b59d3a2016-06-13 12:52:20 -0400360 oldRemovedApiFile = new File(project.rootDir, 'api/removed.txt')
Yigit Boyar3986e042016-02-08 18:31:38 -0800361}
Alan Viverettedd377c92016-06-24 09:51:49 -0400362createArchive.dependsOn checkApi
Yigit Boyar3986e042016-02-08 18:31:38 -0800363
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800364subprojects {
Alan Viverettecc5197e2016-06-13 12:45:07 -0400365 // Only modify android projects.
366 if (project.name.equals('doclava')) return;
367
Yigit Boyar3986e042016-02-08 18:31:38 -0800368 // current SDK is set in studioCompat.gradle
369 project.ext.currentSdk = gradle.ext.currentSdk
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800370 apply plugin: 'maven'
Yigit Boyar3986e042016-02-08 18:31:38 -0800371 project.ext.createApiSourceSets = this.&createApiSourceset
372 project.ext.setApiModuleDependencies = this.&setApiModuleDependencies
373
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800374 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800375 group = 'com.android.support'
376
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700377 repositories {
378 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
379 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
380 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
381 }
382
Jeff Davidson84faec52014-06-18 09:10:36 -0700383 project.plugins.whenPluginAdded { plugin ->
Chris Banese17c5192016-06-01 13:36:05 +0100384 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
385 || "com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
Jeff Davidson84faec52014-06-18 09:10:36 -0700386 project.android.buildToolsVersion = rootProject.buildToolsVersion
Yigit Boyard8d42d52016-04-12 18:20:18 -0700387 // enable code coverage for debug builds only if we are not running inside the IDE
388 // enabling coverage reports breaks the method parameter resolution in the IDE debugger
389 project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
Jeff Davidson84faec52014-06-18 09:10:36 -0700390 }
Alan Viverette573630e2016-07-08 17:17:47 -0400391
392 // Create release and separate zip task for Android libraries (and android-annotations,
393 // which is just a Java library).
394 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
395 || "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)) {
396 task release(type: Upload) {
397 configuration = configurations.archives
398 repositories {
399 mavenDeployer {
400 repository(url: uri("$rootProject.ext.supportRepoOut"))
401
402 // Disable unique names for SNAPSHOTS so they can be updated in place.
403 setUniqueVersion(false)
404 doLast {
405 // Remove any invalid maven-metadata.xml files that may have been
406 // created for SNAPSHOT versions that are *not* uniquely versioned.
407 pom*.each { pom ->
408 if (pom.version.endsWith('-SNAPSHOT')) {
409 final File artifactDir = new File(
410 rootProject.ext.supportRepoOut,
411 pom.groupId.replace('.', '/')
412 + '/' + pom.artifactId
413 + '/' + pom.version)
414 delete fileTree(dir: artifactDir,
415 include: 'maven-metadata.xml*')
416 }
417 }
418 }
419 }
420 }
421 }
422
423 def deployer = release.repositories.mavenDeployer
424 deployer.pom*.whenConfigured { pom ->
425 pom.dependencies.findAll { dep ->
426 dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations'
427 }*.type = 'aar'
428 }
429
430 ext.versionDir = {
431 def groupDir = new File(rootProject.ext.supportRepoOut,
432 project.group.replace('.','/'))
433 def artifactDir = new File(groupDir, archivesBaseName)
434 return new File(artifactDir, version)
435 }
436
437 task generateSourceProps(dependsOn: createRepository) << {
438 def content = "Maven.GroupId=$deployer.pom.groupId\n" +
439 "Maven.ArtifactId=$deployer.pom.artifactId\n" +
440 "Maven.Version=$deployer.pom.version\n" +
441 "Pkg.Desc=$project.name\n" +
442 "Pkg.Revision=1\n" +
443 "Dependencies=" +
444 String.join(",", project.configurations.compile.allDependencies.collect {
445 def p = parent.findProject(it.name)
446 return p ? "$p.group:$p.archivesBaseName:$p.version" : null
447 }.grep()) +
448 "\n"
449 Files.write(content, new File(versionDir(), 'source.properties'), Charsets.UTF_8)
450 }
451
452 task createSeparateZip(type: Zip, dependsOn: generateSourceProps) {
453 into archivesBaseName
454 destinationDir project.parent.ext.distDir
455 baseName = project.group
456 version = project.parent.ext.buildNumber
457 }
458 project.parent.createArchive.dependsOn createSeparateZip
459
460 // before the upload, make sure the repo is ready.
461 release.dependsOn rootProject.tasks.prepareRepo
462 // make the mainupload depend on this one.
463 mainUpload.dependsOn release
464 }
Jeff Davidson84faec52014-06-18 09:10:36 -0700465 }
Chris Banesdaea0692015-12-29 12:48:24 +0000466
Chris Banesdaea0692015-12-29 12:48:24 +0000467 project.afterEvaluate {
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700468 // The archivesBaseName isn't available intially, so set it now
Alan Viverette573630e2016-07-08 17:17:47 -0400469 def createZipTask = project.tasks.findByName("createSeparateZip")
470 if (createZipTask != null) {
471 createZipTask.appendix = archivesBaseName
472 createZipTask.from versionDir()
473 }
Joe Baker-Malone5e2c51d2016-05-13 15:09:24 -0700474
475 // Copy instrumentation test APK into the dist dir
Chris Banesdaea0692015-12-29 12:48:24 +0000476 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
477 if (assembleTestTask != null) {
478 assembleTestTask.doLast {
479 // If the project actually has some instrumentation tests, copy its APK
480 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
481 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
482 copy {
483 from(pkgTask.outputFile)
484 into(rootProject.ext.testApkDistOut)
485 }
486 }
487 }
488 }
489 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800490
491 project.afterEvaluate { p ->
492 // remove dependency on the test so that we still get coverage even if some tests fail
493 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
494 def toBeRemoved = new ArrayList()
495 def dependencyList = task.taskDependencies.values
496 dependencyList.each { dep ->
497 if (dep instanceof String) {
498 def t = tasks.findByName(dep)
499 if (t instanceof DeviceProviderInstrumentTestTask) {
500 toBeRemoved.add(dep)
501 task.mustRunAfter(t)
502 }
503 }
504 }
505 toBeRemoved.each { dep ->
506 dependencyList.remove(dep)
507 }
508 }
509 }
Alan Viverettecc5197e2016-06-13 12:45:07 -0400510
511 project.afterEvaluate { p ->
512 if (p.hasProperty('android')
513 && p.android.hasProperty('libraryVariants')
514 && !(p.android.hasProperty('noDocs') && p.android.noDocs)) {
515 p.android.libraryVariants.all { v ->
516 if (v.name == 'release') {
Alan Viverette9562a3b2016-07-01 13:26:39 -0400517 registerForDocsTask(rootProject.generateDocs, p, v)
518 registerForDocsTask(rootProject.generateApi, p, v)
Alan Viverettecc5197e2016-06-13 12:45:07 -0400519 }
520 }
521 }
522 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800523}
524
Chris Banes9ae4ee82015-09-11 10:32:15 +1000525project.gradle.buildFinished { buildResult ->
526 if (buildResult.getFailure() != null) {
527 println()
528 println 'Build failed. Possible causes include:'
529 println ' 1) Bad codes'
530 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100531 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000532 println()
533 }
534}