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