-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.gradle.kts
144 lines (120 loc) · 4.06 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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt
plugins {
alias(libs.plugins.versionsBenManes)
alias(libs.plugins.versionCatalogUpdate)
alias(libs.plugins.kover)
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.detekt)
}
allprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
}
detekt {
source = objects.fileCollection().from(
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_KOTLIN,
)
config = rootProject.files("config/detekt/detekt.yml")
buildUponDefaultConfig = true
}
tasks.withType<Detekt>().configureEach {
reports {
xml.required.set(true)
html.required.set(true)
sarif.required.set(true)
}
}
buildscript {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}
repositories {
google()
mavenCentral()
}
dependencies {
val formatting = rootProject.libs.plugins.detektFormatting.get()
detektPlugins("${formatting.pluginId}:${formatting.version}")
}
}
kover {}
// ReleaseType/DependencyUpdates are copied from:
// https://github.com/chrisbanes/tivi/blob/main/buildSrc/src/main/java/app/tivi/buildsrc/DependencyUpdates.kt
// Check header for license
enum class ReleaseType(private val level: Int) {
SNAPSHOT(0),
DEV(1),
ALPHA(10),
BETA(20),
RC(60),
RELEASE(100);
fun isEqualOrMoreStableThan(other: ReleaseType): Boolean = level >= other.level
fun isLessStableThan(other: ReleaseType): Boolean = level < other.level
}
object DependencyUpdates {
private val stableKeywords = arrayOf("RELEASE", "FINAL", "GA")
private val releaseRegex = "^[0-9,.v-]+(-r)?$".toRegex(RegexOption.IGNORE_CASE)
private val rcRegex = releaseKeywordRegex("rc")
private val betaRegex = releaseKeywordRegex("beta")
private val alphaRegex = releaseKeywordRegex("alpha")
private val devRegex = releaseKeywordRegex("dev")
fun versionToRelease(version: String): ReleaseType {
val stableKeyword = stableKeywords.any { version.uppercase().contains(it) }
if (stableKeyword) return ReleaseType.RELEASE
return when {
releaseRegex.matches(version) -> ReleaseType.RELEASE
rcRegex.matches(version) -> ReleaseType.RC
betaRegex.matches(version) -> ReleaseType.BETA
alphaRegex.matches(version) -> ReleaseType.ALPHA
devRegex.matches(version) -> ReleaseType.DEV
else -> ReleaseType.SNAPSHOT
}
}
private fun releaseKeywordRegex(keyword: String): Regex {
return "^[0-9,.v-]+(-$keyword[0-9]*)$".toRegex(RegexOption.IGNORE_CASE)
}
}
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
val current = DependencyUpdates.versionToRelease(currentVersion)
if (current == ReleaseType.SNAPSHOT) {
return@rejectVersionIf true
}
val candidate = DependencyUpdates.versionToRelease(candidate.version)
return@rejectVersionIf candidate.isLessStableThan(current)
}
}
val dummyGoogleServices: Configuration by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
attributes {
attribute(Attribute.of("google.services.json", String::class.java), "dummy-json")
}
}
dependencies {
dummyGoogleServices(files(rootProject.file("config/dummy-google-services.json")))
}
versionCatalogUpdate {
keep {
plugins.set(mutableListOf(
libs.plugins.kotlinParcelize,
libs.plugins.detektFormatting
))
}
}