forked from firebase/FirebaseUI-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
388 lines (329 loc) · 13.4 KB
/
build.gradle.kts
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
import com.android.build.gradle.BaseExtension
import com.jfrog.bintray.gradle.BintrayExtension
import com.jfrog.bintray.gradle.tasks.RecordingCopyTask
import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention
import org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
classpath(Config.Plugins.android)
classpath(Config.Plugins.kotlin)
classpath(Config.Plugins.google)
classpath(Config.Plugins.bintray)
classpath(Config.Plugins.buildInfo)
}
}
// See https://github.com/gradle/kotlin-dsl/issues/607#issuecomment-375687119
subprojects { parent!!.path.takeIf { it != rootProject.path }?.let { evaluationDependsOn(it) } }
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
// Skip Javadoc generation for Java 1.8 as it breaks build
if (JavaVersion.current().isJava8Compatible) {
tasks.withType<Javadoc> {
options {
this as StandardJavadocDocletOptions
addStringOption("Xdoclint:none", "-quiet")
}
}
}
if ((group as String).isNotEmpty() && name != "lint" && name != "internal") {
configureAndroid()
configureQuality()
if (Config.submodules.contains(name) || isLibrary) {
setupPublishing()
}
}
}
tasks.withType<Wrapper> {
distributionType = Wrapper.DistributionType.ALL
}
val Project.configDir get() = "$rootDir/library/quality"
val Project.reportsDir get() = "$buildDir/reports"
/**
* Determines if a Project is the 'library' module
*/
val Project.isLibrary get() = name == "library"
/**
* Returns the maven artifact name for a Project.
*/
val Project.artifactName get() = if (isLibrary) "firebase-ui" else "firebase-ui-$name"
/**
* Returns the name for a Project's maven publication.
*/
val Project.publicationName get() = if (isLibrary) "monolithLibrary" else "${name}Library"
fun Project.configureAndroid() {
if (name == "app" || name == "proguard-tests") {
apply(plugin = "com.android.application")
} else {
apply(plugin = "com.android.library")
}
configure<BaseExtension> {
compileSdkVersion(Config.SdkVersions.compile)
defaultConfig {
minSdkVersion(Config.SdkVersions.min)
targetSdkVersion(Config.SdkVersions.target)
versionName = Config.version
versionCode = 1
resourcePrefix("fui_")
vectorDrawables.useSupportLibrary = true
}
lintOptions {
disable(
"ObsoleteLintCustomCheck", // ButterKnife will fix this in v9.0
"IconExpectedSize",
"InvalidPackage", // Firestore uses GRPC which makes lint mad
"NewerVersionAvailable", "GradleDependency", // For reproducible builds
"SelectableText", "SyntheticAccessor" // We almost never care about this
)
disable("UnknownNullness") // TODO fix in future PR
isCheckAllWarnings = true
isWarningsAsErrors = true
isAbortOnError = true
baselineFile = file("$configDir/lint-baseline.xml")
htmlOutput = file("$reportsDir/lint-results.html")
xmlOutput = file("$reportsDir/lint-results.xml")
}
}
}
fun Project.configureQuality() {
apply(plugin = "checkstyle")
configure<CheckstyleExtension> { toolVersion = "8.10.1" }
check { dependsOn("checkstyle") }
task<Checkstyle>("checkstyle") {
configFile = file("$configDir/checkstyle.xml")
source("src")
include("**/*.java")
exclude("**/gen/**")
classpath = files()
}
}
fun Project.setupPublishing() {
val sourcesJar = task<Jar>("sourcesJar") {
classifier = "sources"
from(project.the<BaseExtension>().sourceSets["main"].java.srcDirs)
}
val javadoc = task<Javadoc>("javadoc") {
setSource(project.the<BaseExtension>().sourceSets["main"].java.srcDirs)
classpath += configurations["compile"]
classpath += project.files(project.the<BaseExtension>().bootClasspath)
}
val javadocJar = task<Jar>("javadocJar") {
dependsOn(javadoc)
classifier = "javadoc"
from(javadoc.destinationDir)
}
artifacts.add("archives", javadocJar)
artifacts.add("archives", sourcesJar)
tasks.whenTaskAdded {
if (name.contains("publish") && name.contains("publication", true)) {
dependsOn("assembleRelease")
}
}
afterEvaluate {
if (isLibrary) {
task("testAll") {
dependsOn(*Config.submodules.map {
":$it:testDebugUnitTest"
}.toTypedArray())
}
task("prepareArtifacts") {
dependsOn(javadocJar, sourcesJar, "assembleRelease")
dependsOn("generatePomFileForMonolithLibraryPublication")
dependsOn(*Config.submodules.map {
":$it:prepareArtifacts"
}.toTypedArray())
}
task("publishAllToMavenLocal") {
dependsOn("publishMonolithLibraryPublicationToMavenLocal")
dependsOn(*Config.submodules.map {
":$it:publish${it.capitalize()}LibraryPublicationToMavenLocal"
}.toTypedArray())
}
task("publishAllToCustomLocal") {
dependsOn("publishMonolithLibraryPublicationToCustomLocalRepository")
dependsOn(*Config.submodules.map {
":$it:publish${it.capitalize()}LibraryPublicationToCustomLocalRepository"
}.toTypedArray())
}
task("bintrayUploadAll") {
dependsOn("bintrayUpload")
dependsOn(*Config.submodules.map {
":$it:bintrayUpload"
}.toTypedArray())
}
} else {
val pomTask = "generatePomFileFor${project.name.capitalize()}LibraryPublication"
task("prepareArtifacts") {
dependsOn(javadocJar, sourcesJar, "assembleRelease", pomTask)
}
}
tasks["bintrayUpload"].dependsOn("prepareArtifacts")
}
apply(plugin = "maven-publish")
apply(plugin = "com.jfrog.artifactory")
apply(plugin = "com.jfrog.bintray")
configure<PublishingExtension> {
repositories {
maven {
name = "CustomLocal"
// By passing -Pcustom_local=/some/path and running the
// publishLibraryPublicationToCustomLocalRepository task you can publish this library to a
// custom maven repository location on your machine.
url = uri(properties["custom_local"] ?: "/tmp/")
}
maven {
name = "BuildLocal"
url = uri("$buildDir/repo")
}
}
// We need to override the variables 'group' and 'version' on the 'Project' object in order
// to prevent the bintray plugin from creating 'unspecified' artifacts.
val groupName = "com.firebaseui"
group = groupName
version = Config.version
publications {
create<MavenPublication>(publicationName) {
groupId = groupName
artifactId = artifactName
version = Config.version
val releaseAar = "$buildDir/outputs/aar/${project.name}-release.aar"
logger.info("""
|Creating maven publication '$publicationName'
| Group: $groupName
| Artifact: $artifactName
| Version: $version
| Aar: $releaseAar
""".trimMargin())
artifact(releaseAar)
artifact(javadocJar)
artifact(sourcesJar)
pom {
name.set("FirebaseUI ${project.name.capitalize()}")
description.set("Firebase UI for Android")
url.set("https://github.com/firebase/FirebaseUI-Android")
organization {
name.set("Firebase")
url.set("https://github.com/firebase")
}
scm {
val scmUrl = "scm:git:[email protected]/firebase/firebaseui-android.git"
connection.set(scmUrl)
developerConnection.set(scmUrl)
url.set([email protected])
tag.set("HEAD")
}
developers {
developer {
id.set("samtstern")
name.set("Sam Stern")
email.set("[email protected]")
organization.set("Firebase")
organizationUrl.set("https://firebase.google.com")
roles.set(listOf("Project-Administrator", "Developer"))
timezone.set("-8")
}
developer {
id.set("SUPERCILEX")
name.set("Alex Saveau")
email.set("[email protected]")
roles.set(listOf("Developer"))
timezone.set("-8")
}
}
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
withXml {
asNode().appendNode("dependencies").apply {
fun Dependency.write(scope: String) = appendNode("dependency").apply {
appendNode("groupId", group)
appendNode("artifactId", if (group == groupName) {
"firebase-ui-$name"
} else {
name
})
appendNode("version", version)
appendNode("scope", scope)
}
for (dependency in configurations["api"].dependencies) {
dependency.write("compile")
}
for (dependency in configurations["implementation"].dependencies) {
dependency.write("runtime")
}
}
}
}
}
}
}
val bintrayUsername = properties["bintrayUser"] as String?
?: System.getProperty("BINTRAY_USER") ?: System.getenv("BINTRAY_USER")
val bintrayKey = properties["bintrayKey"] as String?
?: System.getProperty("BINTRAY_KEY") ?: System.getenv("BINTRAY_KEY")
configure<ArtifactoryPluginConvention> {
setContextUrl("https://oss.jfrog.org")
publish(closureOf<PublisherConfig> {
repository(closureOf<DoubleDelegateWrapper> {
invokeMethod("setRepoKey", "oss-snapshot-local")
invokeMethod("setUsername", bintrayUsername)
invokeMethod("setPassword", bintrayKey)
})
})
}
tasks.withType<ArtifactoryTask> { publications(publicationName) }
configure<BintrayExtension> {
user = bintrayUsername
key = bintrayKey
setPublications(publicationName)
// When uploading, move and rename the generated POM
val pomSrc = "$buildDir/publications/$publicationName/pom-default.xml"
val pomDest = "com/firebaseui/$artifactName/${Config.version}/"
val pomName = "$artifactName-${Config.version}.pom"
val pubLog: (String) -> String = { name ->
val publishing = project.extensions
.getByType(PublishingExtension::class.java)
.publications[name] as MavenPublication
"'$name': ${publishing.artifacts}"
}
logger.info("""
|Bintray configuration for '$publicationName'
| Artifact name: $artifactName
| Artifacts: ${publications.joinToString(transform = pubLog)}
""".trimMargin())
logger.info("""
|POM transformation
| Src: $pomSrc
| Dest: $pomDest
| Name: $pomName
""".trimMargin())
filesSpec(closureOf<RecordingCopyTask> {
from(pomSrc)
into(pomDest)
rename(KotlinClosure1<String, String>({ pomName }))
})
pkg(closureOf<BintrayExtension.PackageConfig> {
repo = "firebase-ui"
name = artifactName
userOrg = "firebaseui"
setLicenses("Apache-2.0")
vcsUrl = "https://github.com/firebase/FirebaseUI-Android.git"
version(closureOf<BintrayExtension.VersionConfig> {
name = Config.version
})
})
}
}