-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
302 lines (265 loc) · 11.2 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import groovy.xml.QName
buildscript {
ext.dataBindingRootFolder = project.projectDir
apply from: 'propLoader.gradle'
ext.addRepos(repositories)
if (ext.dataBindingConfig.addRemoteRepos) {
dependencies {
classpath "com.android.databinding:localizemaven:${dataBindingConfig.extraPluginsVersion}"
}
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:5.2.1'
}
}
subprojects {
if (dataBindingConfig.isIndependent) {
apply plugin: 'maven'
if (dataBindingConfig.addRemoteRepos && !dataBindingConfig.forGradlePlugin) {
apply plugin: 'com.android.databinding.localizemaven'
}
} else {
apply from: "${project.projectDir}/../../buildSrc/base/baseJava.gradle"
}
if (it.name != "compilationTests") {
group = dataBindingConfig.group
version = dataBindingConfig.version
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${dataBindingConfig.mavenRepoDir}")
}
}
}
}
buildscript {
addRepos(repositories)
}
}
if (dataBindingConfig.addRemoteRepos && !dataBindingConfig.forGradlePlugin) {
rootProject.localizeMaven {
localRepoDir = file(dataBindingConfig.megaRepoDir)
otherRepoDirs = dataBindingConfig.localRepositories
}
}
task deleteRepo(type: Delete) {
delete "${dataBindingConfig.mavenRepoDir}/${dataBindingConfig.group.replace('.', '/')}"
}
task deletePrebuildFolder(type: Delete) {
delete "${dataBindingConfig.prebuildFolder}"
}
task deleteEap(type: Delete) {
delete "${dataBindingConfig.eapOutDir}"
}
def buildExtensionsTask = project.tasks.create "buildExtensionsTask", Exec
buildExtensionsTask.workingDir file('extensions').getAbsolutePath()
buildExtensionsTask.commandLine './gradlew'
buildExtensionsTask.args 'clean', 'uploadArchives', '--info', '--stacktrace',
"-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
"-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
"-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
buildExtensionsTask.dependsOn subprojects.uploadArchives
def prepareExtensionPrebuilds = project.tasks.create "prepareExtensionPrebuilds", Exec
prepareExtensionPrebuilds.workingDir file('extensions').getAbsolutePath()
prepareExtensionPrebuilds.commandLine './gradlew'
prepareExtensionPrebuilds.args 'clean', 'preparePrebuilds', '--info', '--stacktrace',
"-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
"-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
"-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
prepareExtensionPrebuilds.dependsOn subprojects.uploadArchives
file('integration-tests').listFiles().findAll { it.isDirectory() }.each {
println("Creating run test task for ${it.getAbsolutePath()}.")
def testTask = project.tasks.create "runTestsOf${it.getName().capitalize()}", Exec
testTask.workingDir it.getAbsolutePath()
//on linux
testTask.commandLine './gradlew'
testTask.args 'clean', 'connectedCheck', '--info', '--stacktrace',
"-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
"-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
"-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
testTask.dependsOn subprojects.uploadArchives
}
task runIntegrationTests {
dependsOn tasks.findAll { task -> task.name.startsWith('runTestsOf') }
}
task runAllTests {
dependsOn runIntegrationTests
}
task preparePrebuilds() {
dependsOn deletePrebuildFolder
dependsOn prepareExtensionPrebuilds
}
allprojects {
afterEvaluate { project ->
runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('test')}
runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('connectedCheck')}
preparePrebuilds.dependsOn project.tasks.findAll {task -> task.name.startsWith('prebuild')}
}
}
subprojects.uploadArchives.each { it.shouldRunAfter deleteRepo }
subprojects.uploadArchives.each { it.shouldRunAfter deletePrebuildFolder }
buildExtensionsTask.shouldRunAfter deleteRepo
tasks['runTestsOfMultiModuleTestApp'].dependsOn tasks['runTestsOfIndependentLibrary']
task rebuildRepo() {
dependsOn deleteRepo
dependsOn subprojects.uploadArchives
}
task copySamplesToEap(type : Copy) {
mustRunAfter deleteEap
from ("$projectDir/samples") {
exclude "**/build"
exclude "**/local.properties"
}
into "${dataBindingConfig.eapOutDir}/samples"
}
task copyMavenRepoToEap(type : Copy) {
mustRunAfter deleteEap
dependsOn rebuildRepo
from(dataBindingConfig.mavenRepoDir)
into "${dataBindingConfig.eapOutDir}/${dataBindingConfig.mavenRepoName}"
}
tasks.create(name : 'createEapdataBindingConfigFile') << {
def propsFile = new File("${dataBindingConfig.eapOutDir}/databinding.properties")
Properties props = new Properties()
props.setProperty('version', dataBindingConfig.version)
props.setProperty('mavenRepoName', dataBindingConfig.mavenRepoName)
props.store(propsFile.newWriter(), null)
}
task batchEAP() {
dependsOn deleteEap
dependsOn copyMavenRepoToEap
dependsOn copySamplesToEap
dependsOn createEapdataBindingConfigFile
}
def findChildByTag(node, tag) {
return node.children().find {
it.name().getLocalPart().equals(tag)
}
}
def fullJar(project) {
def localizeTask = project.parent.tasks.findByName('localizeDependencies')
if (localizeTask != null) {
localizeTask.dependsOn project.tasks.findByName('buildLicenseNotice')
}
if (!dataBindingConfig.inReleaseBuild) {
return
}
def jarName = project.uploadArchives.repositories.mavenDeployer.pom.artifactId
def workingDir = "${project.buildDir}/intermediates/fullJar"
def fatJar = "${workingDir}/${jarName}-fat.jar"
def proguardJar = "${workingDir}/${jarName}-proguard.jar"
def jarJar = project.jar.archivePath
def runProguard = dataBindingConfig.runProguard
project.configurations {
jarJarArchives
}
project.tasks.create(name: 'fatJar', type: Jar) {
baseName = jarName + '-fat'
doFirst {
file(workingDir).mkdirs()
}
def deps = new HashSet<ResolvedDependency>()
project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
if (!it.moduleGroup.startsWith('com.android.tools')) {
deps.addAll(it.allModuleArtifacts)
}
}
from { deps.findAll { !it.name.contains('baseLibrary') && !it.name.contains("juniversalchardet")}.collect {
it.file.isDirectory() ? it.file : project.zipTree(it.file)
} } {
exclude "META-INF/maven/**"
exclude "META-INF/MANIFEST.MF"
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
exclude "META-INF/services/javax.annotation.processing.Processor"
exclude "**/*.stg"
}
archiveName "${baseName}.jar"
destinationDir = new File(workingDir)
with project.jar
}
/**
* not used unless jarJarFile is changed to use proguarded version instead.
*/
project.tasks.create(name: 'proguard', type: proguard.gradle.ProGuardTask) {
dependsOn 'fatJar'
injars fatJar
outjars proguardJar
configuration '../proguard.cfg'
}
project.tasks.create(name: 'jarJarFile') {
dependsOn runProguard ? 'proguard' : 'fatJar'
dependsOn project.jar
def inputLibrary = runProguard ? proguardJar : fatJar
def outputLibrary = jarJar
inputs.file(inputLibrary)
outputs.file(outputLibrary)
doLast {
def jarJarLibrary = new File(dataBindingConfig.externalPrebuiltsBase,
'tools/common/m2/repository/com/googlecode/jarjar/jarjar/1.4/jarjar-1.4.jar').
getCanonicalPath()
// in Ant
ant.taskdef(name: "jarjarIt",
classname: 'com.tonicsystems.jarjar.JarJarTask',
classpath: jarJarLibrary)
// start jarjar task
ant.jarjarIt(jarfile: outputLibrary) {
// input is our inputLibrary
zipfileset(src: inputLibrary)
// rule to repackage antlr to new package
rule pattern: 'org.antlr.**', result: 'com.google.repacked.org.antlr.@1'
rule pattern: 'org.abego.treelayout.**', result: 'com.google.repacked.treelayout.@1'
// rule to repackage commons
rule pattern: 'org.apache.**', result: 'com.google.repacked.apache.@1'
rule pattern: 'kotlin.**', result: 'com.google.repacked.kotlin.@1'
}
}
}
def setupUpload = { uploadTask ->
uploadTask.dependsOn 'jarJarFile'
uploadTask.repositories {
mavenDeployer {
pom.whenConfigured { pom ->
pom.dependencies.removeAll { dep ->
def isBaseLibrary = dep.groupId == 'com.android.databinding' &&
dep.artifactId == 'baseLibrary'
def isGradle = dep.groupId == 'com.android.tools.build' &&
dep.artifactId == 'gradle'
def isChardet = dep.groupId == 'com.googlecode.juniversalchardet' &&
dep.artifactId == 'juniversalchardet'
return !isBaseLibrary && !isGradle && !isChardet
}
}
}
}
uploadTask.outputs.upToDateWhen { false } // force it to re-run all the time.
}
if (project.publishLocal != null) {
setupUpload(project.publishLocal)
}
if (project.uploadArchives != null) {
setupUpload(project.uploadArchives)
}
project.bintrayUpload.dependsOn 'jarJarFile'
project.publishing.publications.mavenJava(MavenPublication) {
pom.withXml {
def deps = findChildByTag(asNode(), "dependencies")
if (deps == null) {
throw new IllegalArgumentException("cannot find dependencies in pom file")
}
def unwanted = deps.children().findAll {
def groupId = findChildByTag(it, "groupId").localText()[0]
def artifactId = findChildByTag(it, "artifactId").localText()[0]
def isBaseLibrary = groupId == 'com.android.databinding' &&
artifactId == 'baseLibrary'
def isGradle = groupId == 'com.android.tools.build' && artifactId == 'gradle'
def isChardet = groupId == 'com.googlecode.juniversalchardet' &&
artifactId == 'juniversalchardet'
return !isBaseLibrary && !isGradle && !isChardet
}
unwanted.each {
deps.remove(it)
}
}
}
}