-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
421 lines (388 loc) · 18.7 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
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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
ext {
// https://mvnrepository.com/artifact/androidx.room/room-compiler
// https://mvnrepository.com/artifact/androidx.room/room-runtime
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/room/room-compiler/
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/room/room-runtime/
def room_version = '2.7.0-alpha01'
// https://mvnrepository.com/artifact/com.google.dagger/hilt-android
// https://mvnrepository.com/artifact/com.google.dagger/hilt-compiler
// https://android.googlesource.com/platform/external/dagger2
def hilt_version = '2.47'
// https://mvnrepository.com/artifact/io.github.takahirom.roborazzi/roborazzi
roborazzi_version = '1.29.0'
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-contrib
def espresso_version = '3.6.1'
libs = [
// https://mvnrepository.com/artifact/androidx.annotation/annotation
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/annotation/annotation-jvm/
annotation : 'androidx.annotation:annotation:1.8.0-alpha01',
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/appcompat/appcompat/
appcompat : 'androidx.appcompat:appcompat:1.7.0-beta01',
// https://mvnrepository.com/artifact/androidx.arch.core/core-testing
arch_core_testing : 'androidx.arch.core:core-testing:2.2.0',
// https://mvnrepository.com/artifact/org.awaitility/awaitility
awaitility : 'org.awaitility:awaitility:4.2.2',
// https://mvnrepository.com/artifact/androidx.biometric/biometric
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/biometric/biometric/
biometric : 'androidx.biometric:biometric:1.2.0-alpha05',
// https://mvnrepository.com/artifact/androidx.collection/collection
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/collection/collection-jvm/
collection : 'androidx.collection:collection:1.4.0-alpha02',
// https://mvnrepository.com/artifact/androidx.coordinatorlayout/coordinatorlayout
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/coordinatorlayout/coordinatorlayout/
coordinatorlayout : 'androidx.coordinatorlayout:coordinatorlayout:1.3.0-alpha01',
// https://mvnrepository.com/artifact/androidx.core/core
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/core/core/
core : 'androidx.core:core:1.13.0-beta01',
// https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core
errorprone : 'com.google.errorprone:error_prone_core:2.30.0',
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core
espresso : "androidx.test.espresso:espresso-core:$espresso_version",
espresso_contrib : "androidx.test.espresso:espresso-contrib:$espresso_version",
// https://mvnrepository.com/artifact/org.hamcrest/hamcrest
hamcrest : 'org.hamcrest:hamcrest:3.0',
hilt_android : "com.google.dagger:hilt-android:$hilt_version",
hilt_android_testing : "com.google.dagger:hilt-android-testing:$hilt_version",
hilt_compiler : "com.google.dagger:hilt-compiler:$hilt_version",
// https://mvnrepository.com/artifact/junit/junit
junit : 'junit:junit:4.13.2',
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/lifecycle/lifecycle-livedata/
livedata : 'androidx.lifecycle:lifecycle-livedata:2.8.0-alpha02',
// https://mvnrepository.com/artifact/com.google.android.material/material
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/extras/material-design-x/com/google/android/material/material/
material : 'com.google.android.material:material:1.7.0-alpha03',
// https://mvnrepository.com/artifact/org.mockito/mockito-core
mockito : 'org.mockito:mockito-core:5.13.0',
// https://mvnrepository.com/artifact/androidx.preference/preference
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/preference/preference/
preference : 'androidx.preference:preference:1.2.1',
// https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/recyclerview/recyclerview/
recyclerview : 'androidx.recyclerview:recyclerview:1.4.0-alpha01',
// https://mvnrepository.com/artifact/org.robolectric/robolectric
robolectric : 'org.robolectric:robolectric:4.13',
roborazzi : "io.github.takahirom.roborazzi:roborazzi:$roborazzi_version",
roborazzi_junit_rule : "io.github.takahirom.roborazzi:roborazzi-junit-rule:$roborazzi_version",
// https://mvnrepository.com/artifact/org.robolectric/android-all
robolectric_android_all : 'org.robolectric:android-all:14-robolectric-10818077',
room_compiler : "androidx.room:room-compiler:$room_version",
room_runtime : "androidx.room:room-runtime:$room_version",
room_testing : "androidx.room:room-testing:$room_version",
// https://mvnrepository.com/artifact/androidx.test/core
test_core : 'androidx.test:core:1.6.1',
// https://mvnrepository.com/artifact/androidx.test.ext/junit
test_ext_junit : 'androidx.test.ext:junit:1.2.1',
// https://mvnrepository.com/artifact/androidx.test/rules
test_rules : 'androidx.test:rules:1.6.1',
// https://mvnrepository.com/artifact/androidx.test/runner
test_runner : 'androidx.test:runner:1.6.2',
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/lifecycle/lifecycle-viewmodel/
viewmodel : 'androidx.lifecycle:lifecycle-viewmodel:2.8.0-alpha02'
]
}
dependencies {
classpath "io.github.takahirom.roborazzi:roborazzi-gradle-plugin:$roborazzi_version"
}
}
plugins {
// https://mvnrepository.com/artifact/com.android.application/com.android.application.gradle.plugin
id 'com.android.application' version '8.1.4' apply false
// https://mvnrepository.com/artifact/com.android.library/com.android.library.gradle.plugin
id 'com.android.library' version '8.1.4' apply false
// https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
// https://mvnrepository.com/artifact/net.ltgt.errorprone/net.ltgt.errorprone.gradle.plugin
id 'net.ltgt.errorprone' version '4.0.1' apply false
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kover-gradle-plugin
id 'org.jetbrains.kotlinx.kover' version '0.8.3' apply false
id 'io.github.takahirom.roborazzi' version "$roborazzi_version" apply false
}
allprojects {
plugins.withType(JavaBasePlugin).configureEach {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
ext {
addCompileOnlyJar = { String name ->
final def jars_dir = "$rootDir/prebuilts/jars"
final def jar = new File(jars_dir, name)
if (!jar.exists()) {
throw new IllegalArgumentException("Cannot find prebuilt '${jar.path}' file.")
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile).configureEach {
classpath = files(jar, classpath)
}
tasks.withType(KotlinCompile).configureEach {
libraries.from(files(jar))
}
}
dependencies {
compileOnly files(jar)
}
}
}
}
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-kapt'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'org.jetbrains.kotlinx.kover'
apply plugin: 'io.github.takahirom.roborazzi'
final def versionNameCommon = [file('version.txt').text.trim()]
if (System.getenv('EXTRA_VERSION_BUILD_INFO') == null) {
final def tag = 'v' + versionNameCommon[0]
final def (semver, commitsSinceLastTag, headCommit) = gitDescribeTag(tag, 'HEAD')
versionNameCommon.add('git branch --show-current'.execute([], project.rootDir).text.trim())
versionNameCommon.add(String.format('%s+%s', headCommit, commitsSinceLastTag))
} else {
final def extraVersionBuildInfo = System.getenv('EXTRA_VERSION_BUILD_INFO').trim()
if (!extraVersionBuildInfo.isEmpty()) {
versionNameCommon.add(extraVersionBuildInfo)
}
}
android {
namespace 'com.github.iusmac.sevensim'
buildToolsVersion = '34.0.0'
defaultConfig {
applicationId 'com.github.iusmac.sevensim'
targetSdk 34
versionCode versionNameCommon[0].replaceAll(/\D/, '') as Integer // "x.y.z" => xyz
testInstrumentationRunner 'com.github.iusmac.sevensim.HiltTestRunner'
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}
applicationVariants.all { variant ->
final def versionNameVariant = versionNameCommon.clone()
if (variant.buildType.isDebuggable()) {
versionNameVariant.add('DEBUG')
} else if (isReleaseDebugOpt()) {
versionNameVariant.add('DEBUG-OPT')
}
variant.outputs.each { output ->
final def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
final semVer = versionNameCommon[0]
output.outputFileName = String.format('%s-%s-%s.apk', project.name, semVer,
variant.buildType.name)
}
output.versionNameOverride = versionNameVariant.join(' / ')
}
}
final def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(file('keystore.properties')))
def releaseSigning = signingConfigs.create('release') {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
buildTypes {
all {
buildConfigField 'boolean', 'DEBUG_OPT', 'false'
signingConfig releaseSigning
}
release {
buildConfigField 'boolean', 'DEBUG_OPT', isReleaseDebugOpt().toString()
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard.flags'
}
}
sourceSets {
main {
java.srcDirs = ['src']
res.srcDirs = ['res']
manifest.srcFile 'AndroidManifest.xml'
}
test.java.srcDirs += 'tests/test/java'
debug.assets.srcDirs += files("$projectDir/schemas".toString())
release.assets.srcDirs += files("$projectDir/schemas".toString())
androidTest {
java.srcDirs += 'tests/androidTest/src/java'
res.srcDirs += 'tests/androidTest/res'
manifest.srcFile 'tests/androidTest/AndroidManifest.xml'
}
}
lint {
// Instead of failing the build due to missing translations, just inform us to avoid
// mistakes during manual import
informational 'MissingTranslation'
}
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
packagingOptions.resources.excludes += [
"**/*.bin",
"**/*.properties",
"**/*.version",
"kotlin/**",
"META-INF/services/**",
"META-INF/com/**",
]
tasks.withType(JavaCompile) {
options.errorprone {
enabled = true
disableWarningsInGeneratedCode = true // for @Generated (e.g., Dagger/Hilt, Room)
excludedPaths = '.*/build/generated/.*' // for other generated code
}
}
testOptions {
unitTests {
includeAndroidResources = true
all {
it.systemProperties["robolectric.pixelCopyRenderMode"] = "hardware"
maxHeapSize = "4096m"
}
}
}
}
addCompileOnlyJar('android-34.jar')
dependencies {
implementation libs.annotation
implementation libs.biometric
implementation libs.collection
implementation libs.core
implementation libs.livedata
implementation libs.material
implementation libs.preference
implementation libs.recyclerview
implementation libs.viewmodel
implementation libs.hilt_android
kapt libs.hilt_compiler
kaptTest libs.hilt_compiler
implementation libs.room_runtime
kapt libs.room_compiler
implementation project(path: ':SettingsLib:BannerMessagePreference')
implementation project(path: ':SettingsLib:CollapsingToolbarBaseActivity')
implementation project(path: ':SettingsLib:LayoutPreference')
implementation project(path: ':SettingsLib:SettingsTheme')
implementation project(path: ':SettingsLib:TwoTargetPreference')
testImplementation libs.arch_core_testing
testImplementation libs.awaitility
testImplementation libs.hamcrest
testImplementation (libs.espresso) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation (libs.espresso_contrib) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation libs.junit
testImplementation libs.hilt_android_testing
testImplementation libs.mockito
testImplementation libs.test_core
testImplementation libs.robolectric
testImplementation libs.robolectric_android_all
testImplementation libs.roborazzi
testImplementation libs.roborazzi_junit_rule
testImplementation libs.room_testing
testImplementation libs.test_ext_junit
androidTestImplementation libs.hamcrest
androidTestImplementation (libs.junit) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestImplementation (libs.hilt_android_testing) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestImplementation (libs.test_ext_junit) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestImplementation (libs.test_rules) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestImplementation (libs.test_runner) {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
errorprone libs.errorprone
annotationProcessor libs.errorprone
testAnnotationProcessor libs.errorprone
androidTestAnnotationProcessor libs.errorprone
}
kapt {
correctErrorTypes true
}
kover {
useJacoco()
reports {
filters {
excludes {
// excludes class by fully-qualified JVM class name, wildcards
// '*' and '?' are available
classes(
'*BuildConfig',
'*.Hilt_*',
'*_ComponentTreeDeps',
'*_HiltComponents*',
'*_Impl',
'*_Impl\$*',
)
// excludes all classes located in specified package and it
// subpackages, wildcards '*' and '?' are available
packages(
'com.github.iusmac.sevensim.inject',
'com.github.iusmac.sevensim.ui.components',
'hilt_aggregated_deps',
'dagger.hilt.internal.*',
)
// excludes all classes and functions, annotated by specified
// annotations, wildcards '*' and '?' are available
annotatedBy('*Generated*')
}
}
}
}
/**
* Describe the tag relative to a commit-ish using "git describe".
*
* The result from the git describe command will be transformed as follows:
* "TAG-N-g<commit-ish>" = ["TAG", "N", "commit-ish"]
* "<commit-ish>" = [null, 0, "commit-ish"]
*/
def gitDescribeTag(final String pattern, final String commitIsh) {
final def describedTag = String.format('git describe --always --tags --long --match=%s %s',
pattern, commitIsh).execute([], project.rootDir).text.trim().split('-')
final def tag, commitsSinceLastTag
def headCommit
if (describedTag.size() > 2) {
tag = describedTag[0..-3].join('-')
(commitsSinceLastTag, headCommit) = describedTag[-2..-1]
headCommit = headCommit.substring(1)
} else if (describedTag.size() > 0) {
tag = null
headCommit = describedTag[0]
commitsSinceLastTag = 0
assert(headCommit != null && !headCommit.trim().isEmpty())
} else {
throw new AssertionError('The output from `git describe` command is empty.')
}
return [tag, commitsSinceLastTag, headCommit]
}
/**
* Check whether it was asked to opt-in for debug logging on releases with R8.
*
* The output of this function is determined via:
* - Gradle argument: -PreleaseDebugOpt=[true|false]
* - Environment variable: RELEASE_DEBUG_OPT=[true|false]
*
* Boolean as Integer is allowed.
*/
def isReleaseDebugOpt() {
final def String debugOpt = [
System.getenv('RELEASE_DEBUG_OPT'),
project.properties.releaseDebugOpt
]
return debugOpt.contains('1') || debugOpt.contains('true')
}