This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.gradle.kts
172 lines (160 loc) · 5.77 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
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.BasePlugin
import com.android.build.gradle.LibraryPlugin
import com.diffplug.gradle.spotless.SpotlessExtension
import com.google.devtools.ksp.gradle.KspExtension
import com.google.devtools.ksp.gradle.KspGradleSubplugin
import com.slapin.napt.NaptGradleExtension
import com.slapin.napt.NaptGradlePlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
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.bcv) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.napt) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.cacheFix) apply false
alias(libs.plugins.mavenPublish) apply false
}
allprojects {
if (localGradleProperty("VERSION_NAME").isPresent) {
version = localGradleProperty("VERSION_NAME").get()
group = localGradleProperty("GROUP").get()
}
plugins.apply(rootProject.libs.plugins.detekt.get().pluginId)
configure<DetektExtension> {
config.from("$rootDir/detekt.yml")
parallel = true
}
dependencies {
"detektPlugins"(rootProject.libs.composeRules)
}
plugins.apply(rootProject.libs.plugins.spotless.get().pluginId)
extensions.configure<SpotlessExtension> {
kotlin {
target("src/**/*.kt")
ktlint(rootProject.libs.ktlint.get().version)
}
kotlinGradle {
ktlint(rootProject.libs.ktlint.get().version)
}
}
plugins.withType<BasePlugin> {
plugins.apply(libs.plugins.kotlin.android.get().pluginId)
plugins.apply(libs.plugins.cacheFix.get().pluginId)
if (this is AppPlugin) {
setupCommon()
} else if (this is LibraryPlugin) {
if (displayName.contains(":biz:") || name.startsWith("common")) setupCommon() else setupBase()
}
}
plugins.withType<KspGradleSubplugin>().configureEach {
configure<KspExtension> {
arg("room.generateKotlin", "true")
arg("room.incremental", "true")
}
}
// Configure Java to use our chosen language level. Kotlin will automatically pick this up.
// See https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support
plugins.withType<JavaBasePlugin>().configureEach {
extensions.configure<JavaPluginExtension> {
toolchain.languageVersion = JavaLanguageVersion.of(21)
}
}
plugins.withType<NaptGradlePlugin>().configureEach {
extensions.configure<NaptGradleExtension> {
generateNaptTrigger = false
}
}
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
// Disable this flag due to https://github.com/Goooler/DemoApp/pull/437
// allWarningsAsErrors = true
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
tasks.withType<ValidatePlugins>().configureEach {
failOnWarning = true
enableStricterValidation = true
}
configurations.configureEach {
// https://detekt.dev/docs/gettingstarted/gradle/#gradle-runtime-dependencies
if (name == "detekt") return@configureEach
resolutionStrategy.eachDependency {
when (requested.group) {
libs.androidX.appCompat.get().module.group -> useVersion(libs.androidX.appCompat.get().version.toString())
libs.androidX.activity.compose.get().module.group -> useVersion(libs.androidX.activity.compose.get().version.toString())
libs.androidX.collection.get().module.group -> useVersion(libs.androidX.collection.get().version.toString())
libs.androidX.core.get().module.group -> useVersion(libs.androidX.core.get().version.toString())
libs.androidX.fragment.get().module.group -> useVersion(libs.androidX.fragment.get().version.toString())
libs.kotlin.junit5.get().module.group -> useVersion(libs.kotlin.junit5.get().version.toString())
libs.kotlinX.coroutines.get().group -> when (requested.name) {
libs.kotlinX.coroutines.get().name -> useVersion(libs.kotlinX.coroutines.get().version.toString())
libs.kotlinX.immutable.get().name -> useVersion(libs.kotlinX.immutable.get().version.toString())
}
libs.square.okHttp.logInterceptor.get().module.group -> useVersion(libs.square.okHttp.logInterceptor.get().version.toString())
}
}
}
}
fun <T : BaseExtension> Project.setupBase(block: T.() -> Unit) {
extensions.configure<BaseExtension> {
resourcePrefix = "${name}_"
if (namespace.isNullOrEmpty()) {
namespace = "io.goooler.demoapp.$name"
}
compileSdkVersion(34)
defaultConfig {
minSdk = 21
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets.configureEach {
java.srcDirs("src/$name/kotlin")
}
packagingOptions.resources.excludes += setOf(
"**/*.proto",
"**/*.bin",
"**/*.java",
"**/*.properties",
"**/*.version",
"**/*.*_module",
"*.txt",
"com/**",
"google/**",
"kotlin/**",
"kotlinx/**",
"okhttp3/**",
"META-INF/services/**",
"META-INF/com/**",
"META-INF/licenses/**",
"META-INF/AL2.0",
"META-INF/LGPL2.1",
)
@Suppress("UNCHECKED_CAST")
(this as T).block()
}
}
fun Project.setupBase() {
setupBase<BaseExtension> {}
}
fun Project.setupCommon() {
setupBase<BaseExtension> {
flavorDimensions("env")
productFlavors {
create("dev")
create("prod")
}
}
}
// TODO: remove this once https://github.com/gradle/gradle/issues/23572 is fixed
fun Project.localGradleProperty(name: String): Provider<String> = provider {
if (hasProperty(name)) property(name)?.toString() else null
}