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