-
Notifications
You must be signed in to change notification settings - Fork 222
/
build.gradle.kts
422 lines (363 loc) · 16.9 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import com.android.build.api.dsl.Lint
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.BasePlugin
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.automattic.android.measure.reporters.InternalA8cCiReporter
import com.automattic.android.measure.reporters.SlowSlowTasksMetricsReporter
import com.google.devtools.ksp.gradle.KspExtension
import com.google.devtools.ksp.gradle.KspGradleSubplugin
import io.sentry.android.gradle.extensions.InstrumentationFeature
import io.sentry.android.gradle.extensions.SentryPluginExtension
import java.util.EnumSet
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// Gradle Plugins
dependencies {
// Open source licenses plugin
classpath(libs.osslicenses.plugin)
}
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.aboutlibraries) apply false
alias(libs.plugins.spotless)
alias(libs.plugins.sentry) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.measure.builds)
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.dependency.analysis)
}
apply(from = rootProject.file("dependencies.gradle.kts"))
apply(from = "scripts/git-hooks/install.gradle")
measureBuilds {
enable = project.extra.properties.get("measureBuildsEnabled")?.toString().toBoolean()
onBuildMetricsReadyListener {
val report = this@onBuildMetricsReadyListener
SlowSlowTasksMetricsReporter.report(report)
InternalA8cCiReporter.reportBlocking(
metricsReport = report,
projectName = "pocketcasts",
authToken = project.extra.get("appsMetricsToken").toString(),
)
}
attachGradleScanId = false
}
dependencyAnalysis {
structure {
ignoreKtx(true)
}
issues {
all {
onUsedTransitiveDependencies {
severity("ignore")
}
onRuntimeOnly {
severity("warn")
exclude("org.jetbrains.kotlinx:kotlinx-coroutines-android")
}
onUnusedDependencies {
// Mockito Android is incorrectly reported
// We need it to run instrumentation tests that mock Android classes
exclude("org.mockito:mockito-android")
}
}
project(":app") {
onIncorrectConfiguration {
severity("warn")
exclude("org.jetbrains.kotlin:kotlin-stdlib")
}
}
project(":wear") {
onIncorrectConfiguration {
severity("warn")
exclude("org.jetbrains.kotlin:kotlin-stdlib")
}
}
project(":automotive") {
onIncorrectConfiguration {
severity("warn")
exclude("org.jetbrains.kotlin:kotlin-stdlib")
}
}
}
}
val ktlintVersion = libs.versions.ktlint.get()
spotless {
kotlin {
target(
"app/src/**/*.kt",
"automotive/src/**/*.kt",
"modules/**/src/**/*.kt",
"wear/src/**/*.kt",
)
ktlint(ktlintVersion)
}
kotlinGradle {
target("*.kts")
ktlint(ktlintVersion)
}
}
val javaTarget = JvmTarget.fromTarget(libs.versions.java.get())
allprojects {
configurations.configureEach {
resolutionStrategy.eachDependency {
if (requested.name.startsWith("kotlin-stdlib")) {
useVersion(libs.versions.kotlin.asProvider().get())
}
}
}
}
subprojects {
apply(plugin = rootProject.libs.plugins.dependency.analysis.get().pluginId)
plugins.withType<KotlinBasePlugin>().configureEach {
tasks.withType<KotlinCompilationTask<KotlinJvmCompilerOptions>>().configureEach {
compilerOptions {
jvmTarget.set(javaTarget)
allWarningsAsErrors.set(true)
optIn.addAll("kotlin.RequiresOptIn")
}
}
}
plugins.withType<KspGradleSubplugin>().configureEach {
configure<KspExtension> {
arg("skipPrivatePreviews", "true")
}
}
plugins.withId(rootProject.libs.plugins.sentry.get().pluginId) {
configureSentry()
}
configurations.configureEach {
// Exclude the NDK from the Sentry Android SDK as we don't use it.
exclude("io.sentry", "sentry-android-ndk")
// https://github.com/android/android-test/issues/999
if (name == "androidTestImplementation") {
exclude("com.google.protobuf", "protobuf-lite")
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = javaTarget.target
targetCompatibility = javaTarget.target
}
val configureLint: Lint.() -> Unit = {
baseline = project.file("lint-baseline.xml")
lintConfig = rootProject.file("lint.xml")
xmlReport = true
sarifReport = System.getenv()["CI"].toBoolean()
abortOnError = true
checkAllWarnings = false
warningsAsErrors = false
checkDependencies = true
checkTestSources = false
checkGeneratedSources = false
// Uncomment this when regenerating baseline files
// ignoreWarnings = true
// There's no point in slowing down assembling of release builds
// since we execute lint explicitly on CI in a separate action
checkReleaseBuilds = false
}
val SERVER_MAIN_URL_PROD = "\"https://refresh.pocketcasts.com\""
val SERVER_API_URL_PROD = "\"https://api.pocketcasts.com\""
val SERVER_CACHE_URL_PROD = "\"https://cache.pocketcasts.com\""
val SERVER_CACHE_HOST_PROD = "\"cache.pocketcasts.com\""
val SERVER_STATIC_URL_PROD = "\"https://static.pocketcasts.com\""
val SERVER_SHARING_URL_PROD = "\"https://sharing.pocketcasts.com\""
val SERVER_LIST_URL_PROD = "\"https://lists.pocketcasts.com\""
val SERVER_LIST_HOST_PROD = "\"lists.pocketcasts.com\""
val SERVER_SHORT_URL_PROD = "\"https://pca.st\""
val SERVER_SHORT_HOST_PROD = "\"pca.st\""
val WEB_BASE_HOST_PROD = "\"pocketcasts.com\""
plugins.withType<BasePlugin>().configureEach {
configure<BaseExtension> {
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.toVersion(javaTarget.target)
targetCompatibility = JavaVersion.toVersion(javaTarget.target)
}
setCompileSdkVersion(project.property("compileSdkVersion") as Int)
defaultConfig {
minSdk = project.property("minSdkVersion") as Int
targetSdk = project.property("targetSdkVersion") as Int
versionCode = project.property("versionCode") as Int
versionName = project.property("versionName") as String
buildConfigField("int", "VERSION_CODE", "${project.property("versionCode")}")
buildConfigField("String", "VERSION_NAME", "\"${project.property("versionName")}\"")
buildConfigField("String", "SETTINGS_ENCRYPT_SECRET", "\"${project.property("settingsEncryptSecret")}\"")
buildConfigField("String", "SHARING_SERVER_SECRET", "\"${project.property("sharingServerSecret")}\"")
buildConfigField("String", "GOOGLE_SIGN_IN_SERVER_CLIENT_ID", "\"${project.property("googleSignInServerClientId")}\"")
buildConfigField("String", "SENTRY_DSN", "\"${project.property("pocketcastsSentryDsn")}\"")
buildConfigField("String", "BUILD_PLATFORM", "\"${project.property("buildPlatform")}\"")
buildConfigField("String", "ENCRYPTION_KEY", "\"${project.property("encryptionKey")}\"")
buildConfigField("String", "APP_SECRET", "\"${project.property("appSecret")}\"")
buildConfigField("String", "META_APP_ID", "\"${project.property("metaAppId")}\"")
testInstrumentationRunner = project.property("testInstrumentationRunner") as String
testApplicationId = "au.com.shiftyjelly.pocketcasts.test${project.name.replace("-", "_")}"
vectorDrawables.useSupportLibrary = true
}
testOptions {
animationsDisabled = true
}
packagingOptions.resources.excludes += listOf(
"META-INF/rxjava.properties",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
"META-INF/licenses/ASM",
// Fixes issue running './gradlew connectedDebugAndroidTest' with clashing testing libraries.
"**/attach_hotspot_windows.dll",
)
val canSignRelease = project.property("canSignRelease") == true
signingConfigs {
maybeCreate("debug").apply {
storeFile = rootProject.file("debug.keystore")
storePassword = "debugkey"
keyAlias = "debugkey"
keyPassword = "debugkey"
}
if (canSignRelease) {
maybeCreate("release").apply {
storeFile = project.property("storeFile") as File
storePassword = project.property("storePassword") as String
keyAlias = project.property("keyAlias") as String
keyPassword = project.property("keyPassword") as String
}
}
}
buildTypes {
named("debug") {
isPseudoLocalesEnabled = true
enableUnitTestCoverage = false
enableAndroidTestCoverage = false
ext.set("alwaysUpdateBuildId", false)
buildConfigField("String", "SERVER_MAIN_URL", "\"https://refresh.pocketcasts.net\"")
buildConfigField("String", "SERVER_API_URL", "\"https://api.pocketcasts.net\"")
buildConfigField("String", "SERVER_CACHE_URL", "\"https://podcast-api.pocketcasts.net\"")
buildConfigField("String", "SERVER_CACHE_HOST", "\"podcast-api.pocketcasts.net\"")
buildConfigField("String", "SERVER_STATIC_URL", "\"https://static.pocketcasts.net\"")
buildConfigField("String", "SERVER_SHARING_URL", "\"https://sharing.pocketcasts.net\"")
buildConfigField("String", "SERVER_SHORT_URL", "\"https://pcast.pocketcasts.net\"")
buildConfigField("String", "SERVER_SHORT_HOST", "\"pcast.pocketcasts.net\"")
buildConfigField("String", "WEB_BASE_HOST", "\"pocket-casts-main-development.mystagingwebsite.com\"")
buildConfigField("String", "SERVER_LIST_URL", "\"https://lists.pocketcasts.net\"")
buildConfigField("String", "SERVER_LIST_HOST", "\"lists.pocketcasts.net\"")
signingConfig = signingConfigs.getByName("debug")
}
maybeCreate("debugProd").apply {
isDebuggable = true
isPseudoLocalesEnabled = true
enableUnitTestCoverage = false
enableAndroidTestCoverage = false
ext.set("alwaysUpdateBuildId", false)
buildConfigField("String", "SERVER_MAIN_URL", SERVER_MAIN_URL_PROD)
buildConfigField("String", "SERVER_API_URL", SERVER_API_URL_PROD)
buildConfigField("String", "SERVER_CACHE_URL", SERVER_CACHE_URL_PROD)
buildConfigField("String", "SERVER_CACHE_HOST", SERVER_CACHE_HOST_PROD)
buildConfigField("String", "SERVER_STATIC_URL", SERVER_STATIC_URL_PROD)
buildConfigField("String", "SERVER_SHARING_URL", SERVER_SHARING_URL_PROD)
buildConfigField("String", "SERVER_SHORT_URL", SERVER_SHORT_URL_PROD)
buildConfigField("String", "SERVER_SHORT_HOST", SERVER_SHORT_HOST_PROD)
buildConfigField("String", "WEB_BASE_HOST", WEB_BASE_HOST_PROD)
buildConfigField("String", "SERVER_LIST_URL", SERVER_LIST_URL_PROD)
buildConfigField("String", "SERVER_LIST_HOST", SERVER_LIST_HOST_PROD)
signingConfig = signingConfigs.getByName("debug")
}
named("release") {
buildConfigField("String", "SERVER_MAIN_URL", SERVER_MAIN_URL_PROD)
buildConfigField("String", "SERVER_API_URL", SERVER_API_URL_PROD)
buildConfigField("String", "SERVER_CACHE_URL", SERVER_CACHE_URL_PROD)
buildConfigField("String", "SERVER_CACHE_HOST", SERVER_CACHE_HOST_PROD)
buildConfigField("String", "SERVER_STATIC_URL", SERVER_STATIC_URL_PROD)
buildConfigField("String", "SERVER_SHARING_URL", SERVER_SHARING_URL_PROD)
buildConfigField("String", "SERVER_SHORT_URL", SERVER_SHORT_URL_PROD)
buildConfigField("String", "SERVER_SHORT_HOST", SERVER_SHORT_HOST_PROD)
buildConfigField("String", "WEB_BASE_HOST", WEB_BASE_HOST_PROD)
buildConfigField("String", "SERVER_LIST_URL", SERVER_LIST_URL_PROD)
buildConfigField("String", "SERVER_LIST_HOST", SERVER_LIST_HOST_PROD)
if (canSignRelease) {
signingConfig = signingConfigs.getByName("release")
}
}
}
}
dependencies {
val coreLibraryDesugaring by configurations
coreLibraryDesugaring(libs.desugar.jdk)
}
}
plugins.withType<LibraryPlugin>().configureEach {
configure<LibraryExtension> {
buildTypes {
named("release") {
isMinifyEnabled = false
}
}
}
}
plugins.withType<AppPlugin>().configureEach {
configure<BaseAppModuleExtension> {
lint(configureLint)
buildTypes {
named("debug") {
applicationIdSuffix = ".debug"
}
maybeCreate("debugProd").apply {
applicationIdSuffix = ".debug"
}
named("release") {
isMinifyEnabled = true
proguardFiles.addAll(
listOf(
getDefaultProguardFile("proguard-android-optimize.txt"),
rootProject.file("proguard-rules.pro"),
),
)
isShrinkResources = true
}
}
}
// Set Gradle property 'au.com.shiftyjelly.pocketcasts.leakcanary=true' to enable Leak Canary.
// You can do this using the local.properties file or any other avaialable Gradle mechanism.
// See: https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties
if (properties["au.com.shiftyjelly.pocketcasts.leakcanary"]?.toString().toBoolean()) {
dependencies {
val implementation by configurations
implementation(libs.leakcanary)
}
}
dependencies {
val lintChecks by configurations
lintChecks(libs.security.lint)
}
}
}
fun Project.configureSentry() {
extensions.getByType(SentryPluginExtension::class.java).apply {
val shouldUploadDebugFiles = System.getenv()["CI"].toBoolean() &&
!project.properties["skipSentryProguardMappingUpload"]?.toString().toBoolean()
includeProguardMapping = shouldUploadDebugFiles
includeSourceContext = shouldUploadDebugFiles
tracingInstrumentation {
features.set(EnumSet.allOf(InstrumentationFeature::class.java) - InstrumentationFeature.OKHTTP)
}
autoInstallation.enabled = false
includeDependenciesReport = false
ignoredBuildTypes = setOf("debug", "debugProd")
}
}
tasks.register("aggregatedLintRelease") {
group = "verification"
description = "Run Lint tasks for application modules"
dependsOn(":app:lintRelease", ":automotive:lintRelease", ":wear:lintRelease")
}