blob: 2560b4ffb62473b51db308b1003d43f953cfb58c [file] [log] [blame]
Yigit Boyarb1356332015-05-21 15:49:58 -07001
Yigit Boyar24bec1c2015-07-09 10:51:54 -07002buildscript {
3 ext.rootFolder = project.projectDir
4 apply from: 'propLoader.gradle'
Yigit Boyard6ddc642015-09-11 12:59:40 -07005 apply from: 'supportBundle.gradle'
Yigit Boyar24bec1c2015-07-09 10:51:54 -07006 ext.addRepos(repositories)
7 if (ext.config.addRemoteRepos) {
8 dependencies {
9 classpath "com.android.databinding:localizemaven:${config.extraPluginsVersion}"
10 }
11 }
George Mount69cbd9e2015-08-26 10:46:58 -070012 dependencies {
13 classpath 'net.sf.proguard:proguard-gradle:5.2.1'
14 }
Yigit Boyar24bec1c2015-07-09 10:51:54 -070015}
Yigit Boyar840f0ce2014-12-12 16:45:00 -080016subprojects {
Yigit Boyarf9e51c02015-03-12 14:30:29 -070017 apply plugin: 'maven'
Yigit Boyar24bec1c2015-07-09 10:51:54 -070018 if (config.addRemoteRepos) {
19 apply plugin: 'com.android.databinding.localizemaven'
Yigit Boyar63d47892015-07-10 09:03:05 -070020 }
21
Yigit Boyar24bec1c2015-07-09 10:51:54 -070022 group = config.group
23 version = config.version
Yigit Boyard6ddc642015-09-11 12:59:40 -070024 def url = (config.inReleaseBuild && it.name == "library") ? "file://${config.sharedSupportRepoDir}" : "file://${config.mavenRepoDir}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070025 uploadArchives {
26 repositories {
27 mavenDeployer {
Yigit Boyard6ddc642015-09-11 12:59:40 -070028 repository(url: url)
Yigit Boyarf9e51c02015-03-12 14:30:29 -070029 }
30 }
31 }
Yigit Boyar24bec1c2015-07-09 10:51:54 -070032 buildscript {
33 addRepos(repositories)
34 dependencies {
35 classpath "com.android.databinding:bintray:${config.extraPluginsVersion}"
36 }
37 }
38}
39
40if (config.addRemoteRepos) {
41 localizeMaven {
42 localRepoDir = file(config.megaRepoDir)
43 otherRepoDirs = config.localRepositories
44 }
Yigit Boyarf9e51c02015-03-12 14:30:29 -070045}
46
47task deleteRepo(type: Delete) {
Yigit Boyarb1356332015-05-21 15:49:58 -070048 delete "${config.mavenRepoDir}/${config.group.replace('.', '/')}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070049}
50
Yigit Boyaree758672015-04-16 15:12:02 -070051task deletePrebuildFolder(type: Delete) {
52 delete "${config.prebuildFolder}"
53}
54
Yigit Boyarc64ae352015-04-21 14:05:41 -070055task deleteEap(type: Delete) {
56 delete "${config.eapOutDir}"
57}
58
59
Yigit Boyara6e45832015-03-13 15:58:53 -070060def buildExtensionsTask = project.tasks.create "buildExtensionsTask", Exec
61buildExtensionsTask.workingDir file('extensions').getAbsolutePath()
Yigit Boyara6e45832015-03-13 15:58:53 -070062buildExtensionsTask.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070063buildExtensionsTask.args 'clean', 'uploadArchives', '--info', '--stacktrace',
64 "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}",
65 "-PaddRemoteRepos=${config.addRemoteRepos ? 'true' : 'false'}"
Yigit Boyara6e45832015-03-13 15:58:53 -070066buildExtensionsTask.dependsOn subprojects.uploadArchives
67
Yigit Boyard6ddc642015-09-11 12:59:40 -070068tasks['bundleSupportLib'].dependsOn buildExtensionsTask
69
Yigit Boyaree758672015-04-16 15:12:02 -070070def prepareExtensionPrebuilds = project.tasks.create "prepareExtensionPrebuilds", Exec
71prepareExtensionPrebuilds.workingDir file('extensions').getAbsolutePath()
72prepareExtensionPrebuilds.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070073prepareExtensionPrebuilds.args 'clean', 'preparePrebuilds', '--info', '--stacktrace',
74 "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}",
75 "-PaddRemoteRepos=${config.addRemoteRepos ? 'true' : 'false'}"
Yigit Boyaree758672015-04-16 15:12:02 -070076prepareExtensionPrebuilds.dependsOn subprojects.uploadArchives
77
Yigit Boyarf9e51c02015-03-12 14:30:29 -070078file('integration-tests').listFiles().findAll { it.isDirectory() }.each {
Yigit Boyara6e45832015-03-13 15:58:53 -070079 println("Creating run test task for ${it.getAbsolutePath()}.")
Yigit Boyarf9e51c02015-03-12 14:30:29 -070080 def testTask = project.tasks.create "runTestsOf${it.getName().capitalize()}", Exec
Yigit Boyara6e45832015-03-13 15:58:53 -070081 testTask.workingDir it.getAbsolutePath()
Yigit Boyarf9e51c02015-03-12 14:30:29 -070082 //on linux
83 testTask.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070084 testTask.args 'clean', 'connectedCheck', '--info', '--stacktrace',
85 "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}",
86 "-PaddRemoteRepos=${config.addRemoteRepos ? 'true' : 'false'}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070087 testTask.dependsOn subprojects.uploadArchives
Yigit Boyara6e45832015-03-13 15:58:53 -070088 testTask.dependsOn buildExtensionsTask
Yigit Boyarf9e51c02015-03-12 14:30:29 -070089}
90
91task runIntegrationTests {
92 dependsOn tasks.findAll { task -> task.name.startsWith('runTestsOf') }
93}
94
95task runAllTests {
96 dependsOn runIntegrationTests
97}
98
Yigit Boyaree758672015-04-16 15:12:02 -070099task preparePrebuilds() {
100 dependsOn deletePrebuildFolder
101 dependsOn prepareExtensionPrebuilds
102}
103
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700104allprojects {
105 afterEvaluate { project ->
106 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('test')}
Yigit Boyara6e45832015-03-13 15:58:53 -0700107 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('connectedCheck')}
Yigit Boyaree758672015-04-16 15:12:02 -0700108 preparePrebuilds.dependsOn project.tasks.findAll {task -> task.name.startsWith('prebuild')}
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700109 }
110}
111
Yigit Boyara6e45832015-03-13 15:58:53 -0700112subprojects.uploadArchives.each { it.shouldRunAfter deleteRepo }
Yigit Boyarae161282015-04-21 11:02:58 -0700113subprojects.uploadArchives.each { it.shouldRunAfter deletePrebuildFolder }
Yigit Boyara6e45832015-03-13 15:58:53 -0700114buildExtensionsTask.shouldRunAfter deleteRepo
Yigit Boyar99a3d312015-03-25 12:46:05 -0700115tasks['runTestsOfMultiModuleTestApp'].dependsOn tasks['runTestsOfIndependentLibrary']
Yigit Boyara6e45832015-03-13 15:58:53 -0700116
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700117
118task rebuildRepo() {
119 dependsOn deleteRepo
120 dependsOn subprojects.uploadArchives
Yigit Boyara6e45832015-03-13 15:58:53 -0700121 dependsOn buildExtensionsTask
Yigit Boyaree758672015-04-16 15:12:02 -0700122}
123
Yigit Boyarc64ae352015-04-21 14:05:41 -0700124task copySamplesToEap(type : Copy) {
125 mustRunAfter deleteEap
126 from ("$projectDir/samples") {
127 exclude "**/build"
Yigit Boyar2939c3b2015-04-23 15:03:56 -0700128 exclude "**/local.properties"
Yigit Boyarc64ae352015-04-21 14:05:41 -0700129 }
130 into "${config.eapOutDir}/samples"
131}
132
133
134task copyMavenRepoToEap(type : Copy) {
135 mustRunAfter deleteEap
136 dependsOn rebuildRepo
137 from(config.mavenRepoDir)
138 into "${config.eapOutDir}/${config.mavenRepoName}"
139}
140
141tasks.create(name : 'createEapConfigFile') << {
142 def propsFile = new File("${config.eapOutDir}/databinding.properties")
143 Properties props = new Properties()
Yigit Boyar9399cb42015-05-16 15:42:45 -0700144 props.setProperty('version', config.version)
Yigit Boyarc64ae352015-04-21 14:05:41 -0700145 props.setProperty('mavenRepoName', config.mavenRepoName)
146 props.store(propsFile.newWriter(), null)
147}
148
149
150task batchEAP() {
151 dependsOn deleteEap
152 dependsOn copyMavenRepoToEap
153 dependsOn copySamplesToEap
154 dependsOn createEapConfigFile
Yigit Boyar24bec1c2015-07-09 10:51:54 -0700155}
George Mount69cbd9e2015-08-26 10:46:58 -0700156
157def fullJar(project) {
158 def localizeTask = project.parent.tasks.findByName('localizeDependencies')
159 if (localizeTask != null) {
160 localizeTask.dependsOn project.tasks.findByName('buildLicenseNotice')
161 }
162
Yigit Boyard6ddc642015-09-11 12:59:40 -0700163 if (!config.inReleaseBuild) {
George Mount69cbd9e2015-08-26 10:46:58 -0700164 return
165 }
166 def jarName = project.uploadArchives.repositories.mavenDeployer.pom.artifactId
167 def workingDir = "${project.buildDir}/intermediates/fullJar"
168 def fatJar = "${workingDir}/${jarName}-fat.jar"
169 def proguardJar = "${workingDir}/${jarName}-proguard.jar"
170 def jarJar = project.jar.archivePath
171
172 project.configurations {
173 jarJarArchives
174 }
175
176 project.tasks.create(name: 'fatJar', type: Jar) {
177 baseName = jarName + '-fat'
178 doFirst {
179 file(workingDir).mkdirs()
180 }
181 def deps = new HashSet<ResolvedDependency>()
182 project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
183 if (!it.moduleGroup.startsWith('com.android.tools')) {
184 deps.addAll(it.allModuleArtifacts)
185 }
186 }
187 from { deps.findAll { !it.name.contains('baseLibrary')}.collect {
188 it.file.isDirectory() ? it.file : project.zipTree(it.file)
189 } } {
190 exclude "META-INF/maven/**"
191 exclude "META-INF/MANIFEST.MF"
192 exclude "META-INF/LICENSE.txt"
193 exclude "META-INF/NOTICE.txt"
194 exclude "META-INF/services/javax.annotation.processing.Processor"
195 exclude "**/*.stg"
196 }
197 archiveName "${baseName}.jar"
198 destinationDir = new File(workingDir)
199 with project.jar
200 }
201 project.tasks.create(name: 'proguard', type: proguard.gradle.ProGuardTask) {
202 dependsOn 'fatJar'
203
204 injars fatJar
205 outjars proguardJar
206
207 configuration '../proguard.cfg'
208 }
209
210 project.tasks.create(name: 'jarJarFile') {
211 dependsOn 'proguard'
212 dependsOn project.jar
213 def inputLibrary = proguardJar
214 def outputLibrary = jarJar
215 inputs.file(inputLibrary)
216 outputs.file(outputLibrary)
217
218 doLast {
219 def jarJarLibrary = new File(config.externalPrebuiltsBase,
220 'tools/common/m2/repository/com/googlecode/jarjar/jarjar/1.3/jarjar-1.3.jar').
221 getCanonicalPath()
222 // in Ant
223 ant.taskdef(name: "jarjarIt",
224 classname: 'com.tonicsystems.jarjar.JarJarTask',
225 classpath: jarJarLibrary)
226 // start jarjar task
227 ant.jarjarIt(jarfile: outputLibrary) {
228 // input is our inputLibrary
229 zipfileset(src: inputLibrary)
230 // rule to repackage antlr to new package
231 rule pattern: 'org.antlr.**', result: 'com.google.repacked.antlr.@1'
232 rule pattern: 'com.tunnelvisionlabs.**', result: 'com.google.repacked.tunnelvision.@1'
233 // rule to repackage commons
234 rule pattern: 'org.apache.**', result: 'com.google.repacked.apache.@1'
235 rule pattern: 'kotlin.**', result: 'com.google.repacked.kotlin.@1'
236 }
237 }
238 }
239
240 project.uploadArchives {
241 dependsOn 'jarJarFile'
242 repositories {
243 mavenDeployer {
244 pom.whenConfigured { pom ->
245 pom.dependencies.removeAll { dep ->
246 def isBaseLibrary = dep.groupId == 'com.android.databinding' &&
247 dep.artifactId == 'baseLibrary'
248 def isGradle = dep.groupId == 'com.android.tools.build' &&
249 dep.artifactId == 'gradle'
250 return !isBaseLibrary && !isGradle
251 }
252 }
253 }
254 }
255 }
256}