-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
273 lines (252 loc) · 9.51 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
@file:Suppress("SuspiciousCollectionReassignment", "SpreadOperator")
import java.net.URL
buildscript {
dependencies {
classpath(libs.plugin.kotlinx.atomicfu)
classpath(libs.kotlin.gradle.api)
classpath(libs.kotlin.atomicfu)
}
}
plugins {
id("fluxo-setup")
alias(libs.plugins.android.lib) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.dokka) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlinx.binCompatValidator) apply false
alias(libs.plugins.fluxo.bcv.js) apply false
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.deps.guard)
alias(libs.plugins.deps.versions)
alias(libs.plugins.task.tree)
}
setupDefaults(
multiplatformConfigurator = {
// TODO: Enable the default target hierarchy:
// https://kotlinlang.org/docs/whatsnew1820.html#new-approach-to-source-set-hierarchy
// @OptIn(ExperimentalKotlinGradlePluginApi::class)
// targetHierarchy.default()
explicitApi()
android()
jvm()
if (project.isGenericCompilationEnabled) {
js(IR) {
// Earlier required for generation of TypeScript declaration files
// https://kotlinlang.org/docs/js-ir-compiler.html#preview-generation-of-typescript-declaration-files-d-ts
binaries.executable()
compilations.all {
kotlinOptions {
moduleKind = "es"
useEsClasses = true
sourceMap = true
metaInfo = true
}
}
nodejs()
browser()
generateTypeScriptDefinitions()
}
}
if (Compilations.isGenericEnabled) {
linuxX64()
}
if (Compilations.isWindowsEnabled) {
mingwX64()
}
if (Compilations.isDarwinEnabled) {
iosCompat()
watchosCompat()
tvosCompat()
macosCompat()
}
// Configure a separate test where code runs in worker thread
// https://kotlinlang.org/docs/compiler-reference.html#generate-worker-test-runner-trw
val backgroundNativeTest = false
if (backgroundNativeTest) {
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests<*>>().all {
binaries {
test("background", listOf(DEBUG)) {
freeCompilerArgs += "-trw"
}
}
testRuns {
@Suppress("UNUSED_VARIABLE")
val background by creating {
setExecutionSourceFrom(binaries.getTest("background", DEBUG))
}
}
}
}
},
androidConfig = AndroidConfigSetup(
minSdkVersion = libs.versions.androidMinSdk.get().toInt(),
compileSdkVersion = libs.versions.androidCompileSdk.get().toInt(),
targetSdkVersion = libs.versions.androidTargetSdk.get().toInt(),
buildToolsVersion = libs.versions.androidBuildTools.get(),
configurator = {
if (this is com.android.build.gradle.LibraryExtension) {
// Optimize code with R8 for android release aar
// TODO: On-device tests for aar
buildTypes {
release {
isMinifyEnabled = true
proguardFile(rootProject.file("rules.pro"))
}
}
}
},
),
kotlinConfig = KotlinConfigSetup(
optInInternal = true,
warningsAsErrors = true,
alwaysIndyLambdas = false,
addStdlibDependency = true,
setupCoroutines = false,
optIns = listOf(
"kotlin.js.ExperimentalJsExport",
),
),
publicationConfig = run {
val version = libs.versions.fluxo.get()
val isSnapshot = version.contains("SNAPSHOT", ignoreCase = true)
val scmTag = if (isSnapshot) scmTag().orNull ?: "main" else "v$version"
val url = "https://github.com/fluxo-kt/fluxo"
val publicationUrl = "$url/tree/$scmTag"
PublicationConfig(
// https://central.sonatype.org/publish/publish-gradle/
// https://central.sonatype.org/publish/publish-guide/#initial-setup
// https://central.sonatype.org/publish/requirements/coordinates/#choose-your-coordinates
// https://github.com/jonashackt/github-actions-release-maven
// https://dev.to/kotlin/how-to-build-and-publish-a-kotlin-multiplatform-library-creating-your-first-library-1bp8
group = "io.github.fluxo-kt",
version = version,
projectName = "Fluxo",
projectDescription = "Kotlin Multiplatform MVI / MVVM+ framework",
projectUrl = url,
publicationUrl = publicationUrl,
scmUrl = "scm:git:git://github.com/fluxo-kt/fluxo.git",
scmTag = scmTag,
developerId = "amal",
developerName = "Artyom Shendrik",
developerEmail = "[email protected]",
signingKey = signingKey(),
signingPassword = envOrPropValue("SIGNING_PASSWORD"),
repositoryUserName = envOrPropValue("OSSRH_USER"),
repositoryPassword = envOrPropValue("OSSRH_PASSWORD"),
project = project,
)
},
binaryCompatibilityValidatorConfig = BinaryCompatibilityValidatorConfig(
disableForNonRelease = true,
),
)
setupVerification()
// TODO: Configure universally via convenience plugin
dependencyGuard {
configuration("classpath")
}
koverReport {
dependencies {
kover(projects.fluxoCommon)
kover(projects.fluxoCore)
kover(projects.fluxoData)
}
val isRelease by isRelease()
val isCI by isCI()
defaults {
xml {
onCheck = true
setReportFile(layout.buildDirectory.file("reports/kover-merged-report.xml"))
}
html {
onCheck = !isCI && isRelease
setReportDir(layout.buildDirectory.dir("reports/kover-merged-report-html")) // change report directory
}
verify {
onCheck = true
rule {
isEnabled = true
entity = kotlinx.kover.gradle.plugin.dsl.GroupingEntityType.APPLICATION
minBound(50)
bound {
minValue = 72
metric = kotlinx.kover.gradle.plugin.dsl.MetricType.LINE
aggregation = kotlinx.kover.gradle.plugin.dsl.AggregationType.COVERED_PERCENTAGE
}
bound {
minValue = 65
metric = kotlinx.kover.gradle.plugin.dsl.MetricType.INSTRUCTION
aggregation = kotlinx.kover.gradle.plugin.dsl.AggregationType.COVERED_PERCENTAGE
}
bound {
minValue = 50
metric = kotlinx.kover.gradle.plugin.dsl.MetricType.BRANCH
aggregation = kotlinx.kover.gradle.plugin.dsl.AggregationType.COVERED_PERCENTAGE
}
}
}
}
filters {
excludes {
classes(
*listOfNotNull(
// Test classes
"kt.fluxo.test.*",
"kt.fluxo.tests.*",
// Inline DSL with coverage not detected in release mode.
if (isRelease) "kt.fluxo.core.FluxoKt*" else null,
if (isRelease) "kt.fluxo.core.dsl.MigrationKt*" else null,
).toTypedArray()
)
if (isRelease) {
annotatedBy(
// Coverage is invalid for inline and InlineOnly methods in release mode.
"*Inline*",
// No real need for a deprecated methods' coverage.
"*Deprecated*",
// JvmSynthetic used as a marker for migration helpers hidden from non-kotlin usage and not supposed for coverage.
"*Synthetic*",
)
}
}
}
}
if (hasProperty("buildScan")) {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
val pinnedDeps = libs.bundles.pinned.get().associate {
it.module to it.versionConstraint.toString()
}
allprojects {
if (pinnedDeps.isNotEmpty()) {
configurations.all {
resolutionStrategy.eachDependency {
val version = pinnedDeps[requested.module]
if (version != null) {
useVersion(version)
because("security recommendations or other considerations")
}
}
}
}
plugins.withType<org.jetbrains.dokka.gradle.DokkaPlugin> {
tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dokkaSourceSets {
configureEach {
if (name.startsWith("ios")) {
displayName.set("ios")
}
sourceLink {
localDirectory.set(rootDir)
remoteUrl.set(URL("https://github.com/fluxo-kt/fluxo/blob/main"))
remoteLineSuffix.set("#L")
}
}
}
}
}
}