forked from spotify/android-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
315 lines (269 loc) · 10.2 KB
/
build.gradle.kts
File metadata and controls
315 lines (269 loc) · 10.2 KB
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
/*
* Copyright (c) 2015-2016 Spotify AB
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Properties
import java.io.FileInputStream
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import org.jetbrains.dokka.gradle.DokkaTask
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-parcelize")
id("checkstyle")
id("maven-publish")
id("signing")
id("org.jetbrains.dokka")
}
group = "com.spotify.android"
version = "3.1.0"
val archivesBaseName = "auth"
android {
compileSdk = 33
buildToolsVersion = "33.0.0"
buildFeatures {
buildConfig = true
}
defaultConfig {
minSdk = 16
targetSdk = 33
buildConfigField("String", "LIB_VERSION_NAME", "\"${project.version}\"")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"))
}
}
@Suppress("UnstableApiUsage")
flavorDimensions += "auth"
productFlavors {
create("store") {
dimension = "auth"
}
create("auth") {
dimension = "auth"
isDefault = true
}
}
libraryVariants.configureEach {
outputs.configureEach {
// Rename auth-auth-[buildtype].aar to auth-[buildtype].aar
if (name.startsWith("auth")) {
(this as com.android.build.gradle.internal.api.BaseVariantOutputImpl).outputFileName =
"auth-${buildType.name}.aar"
}
}
}
lint {
lintConfig = file("${project.rootDir}/config/lint.xml")
quiet = false
warningsAsErrors = false
textReport = true
textOutput = file("stdout")
xmlReport = false
}
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
val manifestPlaceholdersForTests = mapOf(
"redirectSchemeName" to "spotify-sdk",
"redirectHostName" to "auth",
"redirectPathPattern" to "/.*"
)
namespace = "com.spotify.sdk.android.auth"
unitTestVariants.configureEach {
mergedFlavor.manifestPlaceholders.putAll(manifestPlaceholdersForTests)
}
testVariants.configureEach {
mergedFlavor.manifestPlaceholders.putAll(manifestPlaceholdersForTests)
}
}
val kotlinVersion = rootProject.extra["kotlin_version"] as String
dependencies {
implementation("androidx.browser:browser:1.5.0")
api("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:2.28.2")
testImplementation("org.robolectric:robolectric:4.11.1")
}
/*
Static analysis section
run: ./gradlew auth-lib:checkstyle auth-lib:findbugs
*/
tasks.register<Checkstyle>("checkstyle") {
configFile = file("${project.rootDir}/config/checkstyle.xml")
source("src")
include("**/*.java")
exclude("**/gen/**")
exclude("**/*.kt")
classpath = files()
}
val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")
signing {
sign(publishing.publications)
}
extra["ossrhUsername"] = ""
extra["ossrhPassword"] = ""
fun getSigningVariables() {
// Try to fetch the values from local.properties, otherwise look in the environment variables
// More info here: https://central.sonatype.org/publish/requirements/gpg/
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
val p = Properties()
FileInputStream(secretPropsFile).use { p.load(it) }
p.forEach { name, value ->
extra[name.toString()] = value
}
} else {
extra["ossrhUsername"] = System.getenv("OSSRH_USERNAME") ?: ""
extra["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") ?: ""
}
}
/*
* Publishing is done through ossrh and can onky be done by people with access.
* reach out to the foss channel to get access.
* https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/
*/
afterEvaluate {
publishing {
repositories {
maven {
getSigningVariables()
name = "ossrh-staging-api"
url = uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/")
credentials {
username = extra["ossrhUsername"].toString()
password = extra["ossrhPassword"].toString()
}
}
}
android.libraryVariants.configureEach {
if (buildType.name == "debug") return@configureEach
val variant = this
val flavored = variant.flavorName != "auth"
val javaDocDir = if (flavored) {
"../docs-${variant.flavorName}/"
} else {
"../docs/"
}
val sourceDirs = variant.sourceSets.flatMap {
it.javaDirectories + it.resourcesDirectories
}
val dokkaTaskName = "${variant.name}Dokka"
if (tasks.findByName(dokkaTaskName) == null) {
tasks.register(dokkaTaskName, DokkaTask::class.java) {
description = "Generates Dokka documentation for ${variant.name}."
// Configure source sets
dokkaSourceSets {
configureEach {
// Include both Kotlin and Java sources
val sourceDirs = variant.sourceSets.flatMap {
it.javaDirectories
}
sourceDirs.forEach { sourceDir ->
if (sourceDir.exists()) {
this@configureEach.sourceRoots.from(sourceDir)
}
}
// Configure classpath
classpath.from(variant.javaCompileProvider.get().classpath)
classpath.from(project.files(android.bootClasspath.joinToString(File.pathSeparator)))
// External documentation links
externalDocumentationLink {
url.set(uri("https://docs.oracle.com/javase/8/docs/api/").toURL())
}
externalDocumentationLink {
url.set(uri("https://developer.android.com/reference/").toURL())
}
// Suppress warnings for undocumented code (optional)
suppressInheritedMembers.set(false)
}
}
// Output directory
outputDirectory.set(file(javaDocDir))
// Fail on warning (set to false during migration)
failOnWarning.set(false)
}
}
val dokkaJarTaskName = "${variant.name}DokkaJar"
if (tasks.findByName(dokkaJarTaskName) == null) {
tasks.register(dokkaJarTaskName, org.gradle.jvm.tasks.Jar::class.java) {
dependsOn(dokkaTaskName)
archiveClassifier.set("javadoc")
from(file(javaDocDir))
}
}
val sourcesJarTaskName = "${variant.name}SourcesJar"
if (tasks.findByName(sourcesJarTaskName) == null) {
tasks.register(sourcesJarTaskName, org.gradle.jvm.tasks.Jar::class.java) {
from(sourceDirs)
archiveClassifier.set("sources")
}
}
val dokkaJar = tasks.named(dokkaJarTaskName)
val sourcesJar = tasks.named(sourcesJarTaskName)
publications {
create<MavenPublication>("${variant.flavorName}Release") {
from(components["${variant.flavorName}Release"])
val suffix = if (flavored) "-${variant.flavorName}" else ""
artifact(dokkaJar)
artifact(sourcesJar)
groupId = project.group.toString()
version = project.version.toString()
artifactId = archivesBaseName + suffix
pom {
name.set(project.group.toString() + ":" + archivesBaseName + suffix)
val descriptionSuffix = if (variant.flavorName == "store") {
" with the Play Store Fallback"
} else {
""
}
description.set("Spotify authorization library for Android$descriptionSuffix")
configurePom()
}
}
}
}
}
}
fun MavenPom.configurePom() {
packaging = "aar"
url.set("https://github.com/spotify/android-auth")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
connection.set("scm:git:https://github.com/spotify/android-auth.git")
developerConnection.set("scm:git:git@github.com:spotify/android-auth.git")
url.set("https://github.com/spotify/android-auth")
}
developers {
developer {
id.set("erikg")
name.set("Erik Ghonyan")
email.set("erikg@spotify.com")
}
}
}