-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
214 lines (192 loc) · 7.44 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
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import com.diffplug.spotless.LineEnding
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath(libs.plugin.agp)
classpath(libs.plugin.kgp)
classpath(libs.plugin.hilt)
}
}
plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.spotless)
}
apply(from = "gradle/projectDependencyGraph.gradle")
allprojects {
// Java
pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(
JavaLanguageVersion.of(libs.versions.android.build.jdk.get().toInt()),
)
}
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(libs.versions.android.build.jdk.get().toInt())
}
}
// Common Android config for both application and library modules
val commonAndroidConfig: CommonExtension<*, *, *, *>.() -> Unit = {
compileSdk = libs.versions.android.build.compileSdk.get().toInt()
buildToolsVersion = libs.versions.android.build.buildToolsVersion.get()
defaultConfig {
minSdk = libs.versions.android.build.minSdk.get().toInt()
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
packaging {
resources {
excludes += listOf(
"META-INF/{AL2.0,LGPL2.1}",
"META-INF/LICENSE.md",
"META-INF/LICENSE-notice.md",
)
}
}
}
// Android config for application modules
pluginManager.withPlugin("com.android.application") {
with(extensions.getByType<ApplicationExtension>()) {
commonAndroidConfig()
defaultConfig {
targetSdk = libs.versions.android.build.targetSdk.get().toInt()
}
}
}
// Android config for library modules
pluginManager.withPlugin("com.android.library") {
with(extensions.getByType<LibraryExtension>()) {
commonAndroidConfig()
defaultConfig {
minSdk = libs.versions.android.build.minSdk.get().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles.add(project.file("consumer-rules.pro"))
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles.addAll(
listOf(
getDefaultProguardFile("proguard-android-optimize.txt"),
project.file("proguard-rules.pro"),
),
)
}
}
testOptions {
unitTests {
isIncludeAndroidResources = true
isReturnDefaultValues = true
}
}
dependencies {
add("coreLibraryDesugaring", libs.android.core.desugaring)
}
}
}
// Detekt
pluginManager.withPlugin("io.gitlab.arturbosch.detekt") {
configure<DetektExtension> {
toolVersion = libs.versions.detekt.get()
allRules = true
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(true)
}
jvmTarget = "11"
excludes.add("**/v3/model/**/*.kt") // exclude generated bigcommerce models
config.setFrom(files(rootProject.file("detekt.yml")))
}
}
// Spotless
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#dependency-resolution-modes
// https://github.com/diffplug/spotless/issues/1213
pluginManager.withPlugin("com.diffplug.spotless") {
val spotlessFormatters: SpotlessExtension.() -> Unit = {
format("misc") {
target("*.md", ".gitignore")
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
target("src/**/*.kt")
targetExclude(
"**/copyright.kt",
"**/v3/model/**/*.kt", // exclude generated bigcommerce models
)
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf(
"disabled_rules" to "filename",
"ij_kotlin_allow_trailing_comma" to "true",
"ij_kotlin_allow_trailing_comma_on_call_site" to "true",
),
)
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "package ")
}
kotlinGradle {
target("src/**/*.kts")
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf(
"disabled_rules" to "filename",
"ij_kotlin_allow_trailing_comma" to "true",
"ij_kotlin_allow_trailing_comma_on_call_site" to "true",
),
)
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
rootProject.file("spotless/copyright.kt"),
"(import|plugins|buildscript|dependencies|pluginManagement)",
)
}
}
configure<SpotlessExtension> {
spotlessFormatters()
// Workaround for Gradle 8.1 configuration cache: https://github.com/diffplug/spotless/issues/1644
lineEndings = LineEnding.PLATFORM_NATIVE
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#dependency-resolution-modes
// https://github.com/diffplug/spotless/issues/1213
if (project.rootProject == project) {
predeclareDeps()
}
if (project.rootProject == project) {
configure<SpotlessExtensionPredeclare> { spotlessFormatters() }
}
}
}
}
subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = libs.versions.android.build.jdk.get()
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}
// Remove kotlinx-coroutines-debug, which is x86 only. Including it causes build errors:
// https://github.com/Kotlin/kotlinx.coroutines/blob/5a71f7b8ec5fd636575a3b6408cbbc9a92b84f11/kotlinx-coroutines-debug/README.md#build-failures-due-to-duplicate-resource-files
configurations.configureEach {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-debug")
}
}