blob: 0f18ae5a758e98987f6535233a4099a8ce11ebda [file] [log] [blame]
Yigit Boyarea5d9b22016-03-08 13:25:26 -08001import com.android.build.gradle.internal.coverage.JacocoReportTask
2import com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask
3
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -08004buildscript {
5 repositories {
6 maven { url '../../prebuilts/gradle-plugin' }
7 maven { url '../../prebuilts/tools/common/m2/repository' }
8 maven { url '../../prebuilts/tools/common/m2/internal' }
Yigit Boyarc9750a12016-01-06 17:28:55 -08009 maven { url "../../prebuilts/maven_repo/android" }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080010 }
11 dependencies {
Yigit Boyarc9750a12016-01-06 17:28:55 -080012 classpath 'com.android.tools.build:gradle:1.5.0'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080013 }
14}
15
Ian Pedowitzc0f4ca62016-02-29 16:21:03 +000016ext.supportVersion = '24.0.0-SNAPSHOT'
17ext.extraVersion = 25
Xavier Ducrohet020e4322014-03-18 16:41:30 -070018ext.supportRepoOut = ''
Yigit Boyarc9750a12016-01-06 17:28:55 -080019ext.buildToolsVersion = '23.0.2'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080020ext.buildNumber = Integer.toString(ext.extraVersion)
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080021
Xavier Ducrohet020e4322014-03-18 16:41:30 -070022/*
23 * With the build server you are given two env variables.
24 * The OUT_DIR is a temporary directory you can use to put things during the build.
25 * The DIST_DIR is where you want to save things from the build.
26 *
27 * The build server will copy the contents of DIST_DIR to somewhere and make it available.
28 */
29if (System.env.DIST_DIR != null && System.env.OUT_DIR != null) {
Xavier Ducrohet4e04b7a2014-10-17 18:02:33 -070030 buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build').getCanonicalFile()
31 project.ext.distDir = new File(System.env.DIST_DIR).getCanonicalFile()
Xavier Ducrohetfa385272014-11-14 13:12:09 -080032
33 // the build server does not pass the build number so we infer it from the last folder of the dist path.
34 ext.buildNumber = project.ext.distDir.getName()
Xavier Ducrohet020e4322014-03-18 16:41:30 -070035} else {
36 buildDir = file('../../out/host/gradle/frameworks/support/build')
37 project.ext.distDir = file('../../out/dist')
38}
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080039
Xavier Ducrohet020e4322014-03-18 16:41:30 -070040ext.supportRepoOut = new File(buildDir, 'support_repo')
Yigit Boyarf18d9752015-12-01 13:45:28 -080041ext.testApkDistOut = ext.distDir
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080042
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070043// Main task called by the build server.
44task(createArchive) << {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070045}
46
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070047
48// upload anchor for subprojects to upload their artifacts
49// to the local repo.
50task(mainUpload) << {
51}
52
53// repository creation task
54task createRepository(type: Zip, dependsOn: mainUpload) {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070055 from project.ext.supportRepoOut
56 destinationDir project.ext.distDir
Xavier Ducrohet9dc44802014-03-20 14:15:16 -070057 into 'm2repository'
Xavier Ducrohetfa385272014-11-14 13:12:09 -080058 baseName = String.format("sdk-repo-linux-m2repository-%s", project.ext.buildNumber)
Xavier Ducrohet020e4322014-03-18 16:41:30 -070059}
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070060createArchive.dependsOn createRepository
Xavier Ducrohet020e4322014-03-18 16:41:30 -070061
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070062// prepare repository with older versions
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070063task unzipRepo(type: Copy) {
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080064 from "$rootDir/../../prebuilts/maven_repo/android"
Xavier Ducrohet855a9222014-01-02 19:00:43 -080065 into project.ext.supportRepoOut
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -080066}
67
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070068unzipRepo.doFirst {
Xavier Ducrohet020e4322014-03-18 16:41:30 -070069 project.ext.supportRepoOut.deleteDir()
70 project.ext.supportRepoOut.mkdirs()
71}
72
Xavier Ducrohet64fe2322014-06-16 17:59:34 -070073// anchor for prepare repo. This is post unzip + sourceProp.
74task(prepareRepo) << {
75}
76
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070077import com.google.common.io.Files
78import com.google.common.base.Charsets
79
80task(createXml) << {
81 def repoArchive = createRepository.archivePath
82 def repoArchiveName = createRepository.archiveName
83 def size = repoArchive.length()
84 def sha1 = getSha1(repoArchive)
85
86 def xml =
87"<sdk:sdk-addon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:sdk=\"http://schemas.android.com/sdk/android/addon/6\">\n\
88 <sdk:extra>\n\
89 <sdk:revision>\n\
90 <sdk:major>${project.ext.extraVersion}</sdk:major>\n\
91 </sdk:revision>\n\
92 <sdk:vendor-display>Android</sdk:vendor-display>\n\
93 <sdk:vendor-id>android</sdk:vendor-id>\n\
94 <sdk:name-display>Local Maven repository for Support Libraries</sdk:name-display>\n\
95 <sdk:path>m2repository</sdk:path>\n\
96 <sdk:archives>\n\
Xavier Ducrohetc16b62d2014-12-09 12:37:45 -080097 <sdk:archive>\n\
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -070098 <sdk:size>${size}</sdk:size>\n\
99 <sdk:checksum type=\"sha1\">${sha1}</sdk:checksum>\n\
100 <sdk:url>${repoArchiveName}</sdk:url>\n\
101 </sdk:archive>\n\
102 </sdk:archives>\n\
103 </sdk:extra>\n\
104</sdk:sdk-addon>"
105
106 Files.write(xml, new File(project.ext.distDir, 'repo-extras.xml'), Charsets.UTF_8)
107}
108createArchive.dependsOn createXml
109
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700110task(createSourceProp) << {
111 def sourceProp =
112"Extra.VendorDisplay=Android\n\
113Extra.Path=m2repository\n\
114Archive.Arch=ANY\n\
115Extra.NameDisplay=Android Support Repository\n\
116Archive.Os=ANY\n\
Alan Viverette5ae24d62016-04-06 16:17:13 -0400117Pkg.Desc=Local Maven repository for Support Libraries\n\
Xavier Ducrohet64fe2322014-06-16 17:59:34 -0700118Pkg.Revision=${project.ext.extraVersion}.0.0\n\
119Extra.VendorId=android"
120
121 Files.write(sourceProp, new File(project.ext.supportRepoOut, 'source.properties'), Charsets.UTF_8)
122}
123createSourceProp.dependsOn unzipRepo
124prepareRepo.dependsOn createSourceProp
125
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700126import com.google.common.hash.HashCode
127import com.google.common.hash.HashFunction
128import com.google.common.hash.Hashing
Chris Banes96f1e912015-03-05 20:04:05 +0000129import java.nio.charset.Charset
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700130
131def getSha1(File inputFile) {
132 HashFunction hashFunction = Hashing.sha1()
Chris Banes96f1e912015-03-05 20:04:05 +0000133 HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charset.forName("UTF-8"))
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700134 return hashCode.toString()
135}
136
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800137subprojects {
138 // Change buildDir first so that all plugins pick up the new value.
Xavier Ducrohet616b95d2014-02-12 09:09:43 -0800139 project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
Yigit Boyar02a9e8c2016-01-26 20:41:00 -0800140 project.ext.currentSdk = 'current'
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800141 apply plugin: 'maven'
142
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800143 version = rootProject.ext.supportVersion
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800144 group = 'com.android.support'
145
Yigit Boyarbe7a54a2015-04-07 13:23:50 -0700146 repositories {
147 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/repository" }
148 maven { url "${project.parent.projectDir}/../../prebuilts/tools/common/m2/internal" }
149 maven { url "${project.parent.projectDir}/../../prebuilts/maven_repo/android" }
150 }
151
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800152 task release(type: Upload) {
153 configuration = configurations.archives
154 repositories {
155 mavenDeployer {
Xavier Ducrohet855a9222014-01-02 19:00:43 -0800156 repository(url: uri("$rootProject.ext.supportRepoOut"))
Justin Klaassen533239e2016-01-09 09:16:23 -0800157
158 // Disable unique names for SNAPSHOTS so they can be updated in place.
159 setUniqueVersion(false)
Justin Klaassend99d7742016-01-21 15:33:57 -0800160 doLast {
161 // Remove any invalid maven-metadata.xml files that may have been created
162 // for SNAPSHOT versions that are *not* uniquely versioned.
163 pom*.each { pom ->
164 if (pom.version.endsWith('-SNAPSHOT')) {
165 final File artifactDir = new File(rootProject.ext.supportRepoOut,
166 pom.groupId.replace('.', '/')
167 + '/' + pom.artifactId
168 + '/' + pom.version)
169 delete fileTree(dir: artifactDir, include: 'maven-metadata.xml*')
170 }
171 }
172 }
Justin Klaassen533239e2016-01-09 09:16:23 -0800173 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800174 }
175 }
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700176
Xavier Ducrohete4cf5a92015-03-06 17:17:30 -0800177 def deployer = release.repositories.mavenDeployer
178 deployer.pom*.whenConfigured { pom ->
179 pom.dependencies.findAll {dep -> dep.groupId == 'com.android.support' && dep.artifactId != 'support-annotations' }*.type = 'aar'
180 }
181
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700182 // before the upload, make sure the repo is ready.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700183 release.dependsOn rootProject.tasks.prepareRepo
Xavier Ducrohet9220b5b2014-03-21 15:30:01 -0700184 // make the mainupload depend on this one.
Xavier Ducrohet020e4322014-03-18 16:41:30 -0700185 mainUpload.dependsOn release
Jeff Davidson84faec52014-06-18 09:10:36 -0700186
187 project.plugins.whenPluginAdded { plugin ->
188 if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
189 project.android.buildToolsVersion = rootProject.buildToolsVersion
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800190 // enable code coverage for debug builds
191 // run createDebugCoverageReport to get the coverage
192 project.android.buildTypes.debug.testCoverageEnabled = true
Jeff Davidson84faec52014-06-18 09:10:36 -0700193 }
194 }
Chris Banesdaea0692015-12-29 12:48:24 +0000195
196 // Copy instrumentation test APK into the dist dir
197 project.afterEvaluate {
198 def assembleTestTask = project.tasks.findByPath('assembleAndroidTest')
199 if (assembleTestTask != null) {
200 assembleTestTask.doLast {
201 // If the project actually has some instrumentation tests, copy its APK
202 if (!project.android.sourceSets.androidTest.java.sourceFiles.isEmpty()) {
203 def pkgTask = project.tasks.findByPath('packageDebugAndroidTest')
204 copy {
205 from(pkgTask.outputFile)
206 into(rootProject.ext.testApkDistOut)
207 }
208 }
209 }
210 }
211 }
Yigit Boyarea5d9b22016-03-08 13:25:26 -0800212
213 project.afterEvaluate { p ->
214 // remove dependency on the test so that we still get coverage even if some tests fail
215 p.tasks.findAll { it instanceof JacocoReportTask}.each { task ->
216 def toBeRemoved = new ArrayList()
217 def dependencyList = task.taskDependencies.values
218 dependencyList.each { dep ->
219 if (dep instanceof String) {
220 def t = tasks.findByName(dep)
221 if (t instanceof DeviceProviderInstrumentTestTask) {
222 toBeRemoved.add(dep)
223 task.mustRunAfter(t)
224 }
225 }
226 }
227 toBeRemoved.each { dep ->
228 dependencyList.remove(dep)
229 }
230 }
231 }
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800232}
233
Chris Banes9ae4ee82015-09-11 10:32:15 +1000234project.gradle.buildFinished { buildResult ->
235 if (buildResult.getFailure() != null) {
236 println()
237 println 'Build failed. Possible causes include:'
238 println ' 1) Bad codes'
239 println ' 2) Out of date prebuilts in prebuilts/sdk'
Chris Banes9e2e8032015-09-16 10:15:37 +0100240 println ' 3) Need to update the compileSdkVersion in a library\'s build.gradle'
Chris Banes9ae4ee82015-09-11 10:32:15 +1000241 println()
242 }
243}
244
Xavier Ducrohet86fb8ef2013-02-22 15:04:37 -0800245FileCollection getAndroidPrebuilt(String apiLevel) {
246 files("$rootDir/../../prebuilts/sdk/$apiLevel/android.jar")
Tor Norbye47c59fb2015-04-08 14:42:16 -0700247}