blob: bd6d4c91b30b9f2de0217c3f025d310c5680e28a [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 Boyard6ddc642015-09-11 12:59:40 -070063buildExtensionsTask.args 'clean', 'uploadArchives', '--info', '--stacktrace', "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}"
Yigit Boyara6e45832015-03-13 15:58:53 -070064buildExtensionsTask.dependsOn subprojects.uploadArchives
65
Yigit Boyard6ddc642015-09-11 12:59:40 -070066tasks['bundleSupportLib'].dependsOn buildExtensionsTask
67
Yigit Boyaree758672015-04-16 15:12:02 -070068def prepareExtensionPrebuilds = project.tasks.create "prepareExtensionPrebuilds", Exec
69prepareExtensionPrebuilds.workingDir file('extensions').getAbsolutePath()
70prepareExtensionPrebuilds.commandLine './gradlew'
Yigit Boyard6ddc642015-09-11 12:59:40 -070071prepareExtensionPrebuilds.args 'clean', 'preparePrebuilds', '--info', '--stacktrace', "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}"
Yigit Boyaree758672015-04-16 15:12:02 -070072prepareExtensionPrebuilds.dependsOn subprojects.uploadArchives
73
Yigit Boyarf9e51c02015-03-12 14:30:29 -070074file('integration-tests').listFiles().findAll { it.isDirectory() }.each {
Yigit Boyara6e45832015-03-13 15:58:53 -070075 println("Creating run test task for ${it.getAbsolutePath()}.")
Yigit Boyarf9e51c02015-03-12 14:30:29 -070076 def testTask = project.tasks.create "runTestsOf${it.getName().capitalize()}", Exec
Yigit Boyara6e45832015-03-13 15:58:53 -070077 testTask.workingDir it.getAbsolutePath()
Yigit Boyarf9e51c02015-03-12 14:30:29 -070078 //on linux
79 testTask.commandLine './gradlew'
Yigit Boyard6ddc642015-09-11 12:59:40 -070080 testTask.args 'clean', 'connectedCheck', '--info', '--stacktrace', "-PuseReleaseVersion=${config.inReleaseBuild ? 'true' : 'false'}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070081 testTask.dependsOn subprojects.uploadArchives
Yigit Boyara6e45832015-03-13 15:58:53 -070082 testTask.dependsOn buildExtensionsTask
Yigit Boyarf9e51c02015-03-12 14:30:29 -070083}
84
85task runIntegrationTests {
86 dependsOn tasks.findAll { task -> task.name.startsWith('runTestsOf') }
87}
88
89task runAllTests {
90 dependsOn runIntegrationTests
91}
92
Yigit Boyaree758672015-04-16 15:12:02 -070093task preparePrebuilds() {
94 dependsOn deletePrebuildFolder
95 dependsOn prepareExtensionPrebuilds
96}
97
Yigit Boyarf9e51c02015-03-12 14:30:29 -070098allprojects {
99 afterEvaluate { project ->
100 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('test')}
Yigit Boyara6e45832015-03-13 15:58:53 -0700101 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('connectedCheck')}
Yigit Boyaree758672015-04-16 15:12:02 -0700102 preparePrebuilds.dependsOn project.tasks.findAll {task -> task.name.startsWith('prebuild')}
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700103 }
104}
105
Yigit Boyara6e45832015-03-13 15:58:53 -0700106subprojects.uploadArchives.each { it.shouldRunAfter deleteRepo }
Yigit Boyarae161282015-04-21 11:02:58 -0700107subprojects.uploadArchives.each { it.shouldRunAfter deletePrebuildFolder }
Yigit Boyara6e45832015-03-13 15:58:53 -0700108buildExtensionsTask.shouldRunAfter deleteRepo
Yigit Boyar99a3d312015-03-25 12:46:05 -0700109tasks['runTestsOfMultiModuleTestApp'].dependsOn tasks['runTestsOfIndependentLibrary']
Yigit Boyara6e45832015-03-13 15:58:53 -0700110
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700111
112task rebuildRepo() {
113 dependsOn deleteRepo
114 dependsOn subprojects.uploadArchives
Yigit Boyara6e45832015-03-13 15:58:53 -0700115 dependsOn buildExtensionsTask
Yigit Boyaree758672015-04-16 15:12:02 -0700116}
117
Yigit Boyarc64ae352015-04-21 14:05:41 -0700118task copySamplesToEap(type : Copy) {
119 mustRunAfter deleteEap
120 from ("$projectDir/samples") {
121 exclude "**/build"
Yigit Boyar2939c3b2015-04-23 15:03:56 -0700122 exclude "**/local.properties"
Yigit Boyarc64ae352015-04-21 14:05:41 -0700123 }
124 into "${config.eapOutDir}/samples"
125}
126
127
128task copyMavenRepoToEap(type : Copy) {
129 mustRunAfter deleteEap
130 dependsOn rebuildRepo
131 from(config.mavenRepoDir)
132 into "${config.eapOutDir}/${config.mavenRepoName}"
133}
134
135tasks.create(name : 'createEapConfigFile') << {
136 def propsFile = new File("${config.eapOutDir}/databinding.properties")
137 Properties props = new Properties()
Yigit Boyar9399cb42015-05-16 15:42:45 -0700138 props.setProperty('version', config.version)
Yigit Boyarc64ae352015-04-21 14:05:41 -0700139 props.setProperty('mavenRepoName', config.mavenRepoName)
140 props.store(propsFile.newWriter(), null)
141}
142
143
144task batchEAP() {
145 dependsOn deleteEap
146 dependsOn copyMavenRepoToEap
147 dependsOn copySamplesToEap
148 dependsOn createEapConfigFile
Yigit Boyar24bec1c2015-07-09 10:51:54 -0700149}
George Mount69cbd9e2015-08-26 10:46:58 -0700150
151def fullJar(project) {
152 def localizeTask = project.parent.tasks.findByName('localizeDependencies')
153 if (localizeTask != null) {
154 localizeTask.dependsOn project.tasks.findByName('buildLicenseNotice')
155 }
156
Yigit Boyard6ddc642015-09-11 12:59:40 -0700157 if (!config.inReleaseBuild) {
George Mount69cbd9e2015-08-26 10:46:58 -0700158 return
159 }
160 def jarName = project.uploadArchives.repositories.mavenDeployer.pom.artifactId
161 def workingDir = "${project.buildDir}/intermediates/fullJar"
162 def fatJar = "${workingDir}/${jarName}-fat.jar"
163 def proguardJar = "${workingDir}/${jarName}-proguard.jar"
164 def jarJar = project.jar.archivePath
165
166 project.configurations {
167 jarJarArchives
168 }
169
170 project.tasks.create(name: 'fatJar', type: Jar) {
171 baseName = jarName + '-fat'
172 doFirst {
173 file(workingDir).mkdirs()
174 }
175 def deps = new HashSet<ResolvedDependency>()
176 project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
177 if (!it.moduleGroup.startsWith('com.android.tools')) {
178 deps.addAll(it.allModuleArtifacts)
179 }
180 }
181 from { deps.findAll { !it.name.contains('baseLibrary')}.collect {
182 it.file.isDirectory() ? it.file : project.zipTree(it.file)
183 } } {
184 exclude "META-INF/maven/**"
185 exclude "META-INF/MANIFEST.MF"
186 exclude "META-INF/LICENSE.txt"
187 exclude "META-INF/NOTICE.txt"
188 exclude "META-INF/services/javax.annotation.processing.Processor"
189 exclude "**/*.stg"
190 }
191 archiveName "${baseName}.jar"
192 destinationDir = new File(workingDir)
193 with project.jar
194 }
195 project.tasks.create(name: 'proguard', type: proguard.gradle.ProGuardTask) {
196 dependsOn 'fatJar'
197
198 injars fatJar
199 outjars proguardJar
200
201 configuration '../proguard.cfg'
202 }
203
204 project.tasks.create(name: 'jarJarFile') {
205 dependsOn 'proguard'
206 dependsOn project.jar
207 def inputLibrary = proguardJar
208 def outputLibrary = jarJar
209 inputs.file(inputLibrary)
210 outputs.file(outputLibrary)
211
212 doLast {
213 def jarJarLibrary = new File(config.externalPrebuiltsBase,
214 'tools/common/m2/repository/com/googlecode/jarjar/jarjar/1.3/jarjar-1.3.jar').
215 getCanonicalPath()
216 // in Ant
217 ant.taskdef(name: "jarjarIt",
218 classname: 'com.tonicsystems.jarjar.JarJarTask',
219 classpath: jarJarLibrary)
220 // start jarjar task
221 ant.jarjarIt(jarfile: outputLibrary) {
222 // input is our inputLibrary
223 zipfileset(src: inputLibrary)
224 // rule to repackage antlr to new package
225 rule pattern: 'org.antlr.**', result: 'com.google.repacked.antlr.@1'
226 rule pattern: 'com.tunnelvisionlabs.**', result: 'com.google.repacked.tunnelvision.@1'
227 // rule to repackage commons
228 rule pattern: 'org.apache.**', result: 'com.google.repacked.apache.@1'
229 rule pattern: 'kotlin.**', result: 'com.google.repacked.kotlin.@1'
230 }
231 }
232 }
233
234 project.uploadArchives {
235 dependsOn 'jarJarFile'
236 repositories {
237 mavenDeployer {
238 pom.whenConfigured { pom ->
239 pom.dependencies.removeAll { dep ->
240 def isBaseLibrary = dep.groupId == 'com.android.databinding' &&
241 dep.artifactId == 'baseLibrary'
242 def isGradle = dep.groupId == 'com.android.tools.build' &&
243 dep.artifactId == 'gradle'
244 return !isBaseLibrary && !isGradle
245 }
246 }
247 }
248 }
249 }
250}