Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
887 lines (825 loc) · 36.4 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
887 lines (825 loc) · 36.4 KB
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
/** Verifies that all configured module ownership documents exist. */
abstract class VerifyModuleDocumentationTask : DefaultTask() {
/** Repository directory used to resolve configured relative paths. */
@get:Internal
abstract val repositoryDirectory: DirectoryProperty
/** Relative ownership-document paths keyed by Gradle project path. */
@get:Input
abstract val documentationPaths: MapProperty<String, String>
/** Ownership documents tracked as task inputs. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val documentationFiles: ConfigurableFileCollection
/** Performs the documentation coverage check. */
@TaskAction
fun verify() {
val repositoryRoot = repositoryDirectory.get().asFile
val undocumentedModules = documentationPaths.get()
.filterValues { relativePath -> !repositoryRoot.resolve(relativePath).isFile }
.keys
.sorted()
check(undocumentedModules.isEmpty()) {
"Missing MODULE.md ownership contract for: ${undocumentedModules.joinToString()}"
}
}
}
/** Verifies direct project dependencies declared by guarded architecture modules. */
abstract class VerifyModuleBoundariesTask : DefaultTask() {
/** Repository directory used to resolve guarded build scripts. */
@get:Internal
abstract val repositoryDirectory: DirectoryProperty
/** Relative build-script paths keyed by guarded Gradle project path. */
@get:Input
abstract val guardedBuildScriptPaths: MapProperty<String, String>
/** Allowed direct project paths, encoded as sorted comma-separated values. */
@get:Input
abstract val allowedDependencies: MapProperty<String, String>
/** Guarded build scripts tracked as task inputs. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val guardedBuildScripts: ConfigurableFileCollection
/** Performs the dependency-boundary check. */
@TaskAction
fun verify() {
val repositoryRoot = repositoryDirectory.get().asFile
val projectDependencyPattern = Regex("project\\(\"(:[^\"]+)\"\\)")
val buildScriptsByModule: Map<String, String> = guardedBuildScriptPaths.get()
val approvedDependenciesByModule: Map<String, String> = allowedDependencies.get()
val violations: List<String> = buildScriptsByModule.entries.flatMap { entry ->
val modulePath = entry.key
val relativeBuildScriptPath = entry.value
val directDependencies = projectDependencyPattern
.findAll(repositoryRoot.resolve(relativeBuildScriptPath).readText())
.map { match -> match.groupValues[1] }
.toSet()
val approvedDependencies = approvedDependenciesByModule.getValue(modulePath)
.split(',')
.filter(String::isNotBlank)
.toSet()
(directDependencies - approvedDependencies).map { dependencyPath ->
"$modulePath must not depend on $dependencyPath"
}
}
check(violations.isEmpty()) {
violations.sorted().joinToString(
prefix = "Target architecture dependency violations:\n",
separator = "\n",
)
}
}
}
/** Prevents presentation modules from importing concrete runtime, storage, or platform adapters. */
abstract class VerifyUiRuntimeIsolationTask : DefaultTask() {
/** Production Kotlin sources under UI modules. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val productionSources: ConfigurableFileCollection
/** UI Gradle build scripts. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val buildScripts: ConfigurableFileCollection
/** Engine packages deliberately approved as presentation-facing typed protocol APIs. */
@get:Input
abstract val allowedEngineImportPrefixes: ListProperty<String>
/** Engine projects deliberately approved as presentation-facing typed protocol APIs. */
@get:Input
abstract val allowedEngineProjects: ListProperty<String>
@TaskAction
fun verify() {
val allowedImports = allowedEngineImportPrefixes.get()
val sourceViolations = productionSources.files.sortedBy { it.path }.flatMap { source ->
source.readLines().mapIndexedNotNull { index, line ->
val imported = line.trim().removePrefix("import ").takeIf { line.trim().startsWith("import ") }
?: return@mapIndexedNotNull null
if (
imported.startsWith("com.devuloopers.knet.engine.") &&
allowedImports.none(imported::startsWith)
) "${source.relativeTo(project.rootDir)}:${index + 1} imports $imported" else null
}
}
val projectPattern = Regex("project\\(\"(:engine:[^\"]+)\"\\)")
val allowedProjects = allowedEngineProjects.get().toSet()
val buildViolations = buildScripts.files.sortedBy { it.path }.flatMap { script ->
projectPattern.findAll(script.readText())
.map { match -> match.groupValues[1] }
.filterNot(allowedProjects::contains)
.map { dependency -> "${script.relativeTo(project.rootDir)} depends on $dependency" }
.toList()
}
val violations = sourceViolations + buildViolations
check(violations.isEmpty()) {
violations.joinToString(
prefix = "UI concrete-runtime dependency violations:\n",
separator = "\n",
)
}
}
}
/** Keeps dependency-injection binding declarations in executable product composition roots. */
abstract class VerifyCompositionOwnershipTask : DefaultTask() {
/** Production sources outside executable products. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val productionSources: ConfigurableFileCollection
@TaskAction
fun verify() {
val bindingImports = listOf(
"import org.koin.dsl.module",
"import org.koin.core.module.dsl.",
)
val violations = productionSources.files.sortedBy { it.path }.flatMap { source ->
source.readLines().mapIndexedNotNull { index, line ->
val trimmed = line.trim()
if (bindingImports.any(trimmed::startsWith)) {
"${source.relativeTo(project.rootDir)}:${index + 1} declares Koin bindings outside a product composition root"
} else {
null
}
}
}
check(violations.isEmpty()) {
violations.joinToString(
prefix = "Dependency-injection composition ownership violations:\n",
separator = "\n",
)
}
}
}
/** Keeps portable and production Kotlin sources on the approved Kotlin-first platform boundary. */
abstract class VerifyKotlinFirstSourcesTask : DefaultTask() {
/** Repository directory used to report stable relative source paths. */
@get:Internal
abstract val repositoryDirectory: DirectoryProperty
/** Kotlin sources compiled as portable common code. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val commonSources: ConfigurableFileCollection
/** Kotlin sources compiled into production artifacts. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val productionSources: ConfigurableFileCollection
/** Every repository Kotlin source, including tests. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val allKotlinSources: ConfigurableFileCollection
/** Kotlin sources in modules that rely on Kotlin's default public visibility. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val implicitApiSources: ConfigurableFileCollection
/** JVM source files allowed to adapt Compose clipboard entries to the desktop runtime. */
@get:Input
abstract val allowedAwtClipboardPaths: ListProperty<String>
/** Verifies common-source portability and prohibited production Java/coroutine shortcuts. */
@TaskAction
fun verify() {
val repositoryRoot = repositoryDirectory.get().asFile
val commonViolations = commonSources.files.sortedBy { it.path }.flatMap { source ->
val relativePath = source.relativeTo(repositoryRoot).invariantSeparatorsPath
val sourceLines = source.codeLines()
val lineViolations = sourceLines.mapNotNull { (lineNumber, line) ->
when {
line.startsWith("import java.") || line.startsWith("import javax.") ->
"$relativePath:$lineNumber imports a JVM API from commonMain"
line.startsWith("import android.") || line.startsWith("import platform.") ->
"$relativePath:$lineNumber imports a native platform API from commonMain"
JVM_QUALIFIED_REFERENCE.containsMatchIn(line) ->
"$relativePath:$lineNumber references a JVM API from commonMain"
SYSTEM_REFERENCE.containsMatchIn(line) ->
"$relativePath:$lineNumber references System from commonMain"
relativePath.startsWith(COMPANION_COMMON_SOURCE_PREFIX) &&
(
COMPANION_NATIVE_CONTEXT_REFERENCE.containsMatchIn(line) ||
COMPANION_OPAQUE_ANY_DECLARATION.containsMatchIn(line)
) ->
"$relativePath:$lineNumber exposes a native context or opaque Any bridge from commonMain"
else -> null
}
}
val factoryConstructorViolation = if (
relativePath == COMPANION_EXPECT_FACTORY_PATH &&
sourceLines.joinToString("\n") { (_, line) -> line }
.contains("expect class PlatformCompanionAdapterFactory(")
) {
listOf("$relativePath declares a common constructor for the native platform factory")
} else {
emptyList()
}
lineViolations + factoryConstructorViolation
}
val approvedClipboardPaths = allowedAwtClipboardPaths.get().toSet()
val productionViolations = productionSources.files.sortedBy { it.path }.flatMap { source ->
val relativePath = source.relativeTo(repositoryRoot).invariantSeparatorsPath
source.codeLines().flatMap { (lineNumber, line) ->
buildList {
if (RUN_BLOCKING_REFERENCE.containsMatchIn(line)) {
add("$relativePath:$lineNumber uses runBlocking in production")
}
if (JAVA_UUID_REFERENCE.containsMatchIn(line)) {
add("$relativePath:$lineNumber uses java.util.UUID")
}
if (AVOIDABLE_JAVA_UTILITY_IMPORT.containsMatchIn(line)) {
add("$relativePath:$lineNumber imports an avoidable Java utility")
}
if (DEPRECATED_COMPOSE_REFERENCE.containsMatchIn(line)) {
add("$relativePath:$lineNumber uses a deprecated Compose API")
}
if (NON_MIRRORED_DIRECTIONAL_ICON.containsMatchIn(line)) {
add("$relativePath:$lineNumber uses a non-auto-mirrored directional icon")
}
if (
AWT_CLIPBOARD_REFERENCE.containsMatchIn(line) &&
relativePath !in approvedClipboardPaths
) {
add("$relativePath:$lineNumber uses AWT clipboard outside the platform adapter")
}
}
}
}
val visibilityViolations = implicitApiSources.files.sortedBy { it.path }.flatMap { source ->
val relativePath = source.relativeTo(repositoryRoot).invariantSeparatorsPath
source.codeLines().mapNotNull { (lineNumber, line) ->
if (REDUNDANT_PUBLIC_VISIBILITY.containsMatchIn(line)) {
"$relativePath:$lineNumber declares redundant public visibility outside an explicit-API module"
} else {
null
}
}
}
val javaTimeViolations = allKotlinSources.files.sortedBy { it.path }.flatMap { source ->
val relativePath = source.relativeTo(repositoryRoot).invariantSeparatorsPath
source.codeLines().mapNotNull { (lineNumber, line) ->
if (JAVA_TIME_REFERENCE.containsMatchIn(line)) {
"$relativePath:$lineNumber uses prohibited java.time; use kotlin.time or kotlinx-datetime"
} else {
null
}
}
}
val violations = commonViolations + productionViolations + visibilityViolations + javaTimeViolations
check(violations.isEmpty()) {
violations.joinToString(
prefix = "Kotlin-first source-boundary violations:\n",
separator = "\n",
)
}
}
/** Returns non-comment source lines with their one-based line numbers. */
private fun java.io.File.codeLines(): List<Pair<Int, String>> {
var insideBlockComment = false
return readLines().mapIndexedNotNull { index, rawLine ->
val line = rawLine.trim()
if (insideBlockComment) {
if (line.contains("*/")) insideBlockComment = false
return@mapIndexedNotNull null
}
if (line.startsWith("/*")) {
if (!line.contains("*/")) insideBlockComment = true
return@mapIndexedNotNull null
}
if (line.isBlank() || line.startsWith("//")) null else index + 1 to line
}
}
private companion object {
val JVM_QUALIFIED_REFERENCE = Regex("""\b(?:java|javax)\.""")
val SYSTEM_REFERENCE = Regex("""(?<!Clock\.)\bSystem\.""")
const val COMPANION_COMMON_SOURCE_PREFIX = "connectivity/companion/src/commonMain/"
const val COMPANION_EXPECT_FACTORY_PATH =
"connectivity/companion/src/commonMain/kotlin/com/devuloopers/knet/companion/connectivity/platform/PlatformCompanionAdapterFactory.kt"
val COMPANION_NATIVE_CONTEXT_REFERENCE = Regex("""\b[A-Za-z0-9_.]*Context\b""")
val COMPANION_OPAQUE_ANY_DECLARATION = Regex("""\b[A-Za-z_][A-Za-z0-9_]*\s*:\s*Any\??\s*[,)=]""")
val RUN_BLOCKING_REFERENCE = Regex("""(?:import kotlinx\.coroutines\.runBlocking|\brunBlocking\s*[({])""")
val JAVA_UUID_REFERENCE = Regex("""\bjava\.util\.UUID\b""")
val JAVA_TIME_REFERENCE = Regex("""\bjava\.time(?:\.|\b)""")
val AVOIDABLE_JAVA_UTILITY_IMPORT = Regex(
"""^import (?:java\.util\.(?:Base64|ArrayDeque|Collections|LinkedHashMap)|java\.net\.(?:URLDecoder|URLEncoder)|java\.nio\.charset\.StandardCharsets|java\.text\.SimpleDateFormat)\b""",
)
val DEPRECATED_COMPOSE_REFERENCE = Regex(
"""(?:androidx\.compose\.desktop\.ui\.tooling\.preview\.Preview|androidx\.compose\.ui\.res\.painterResource)""",
)
val NON_MIRRORED_DIRECTIONAL_ICON = Regex(
"""Icons\.(?:Default|Filled)\.(?:ArrowBack|ArrowForward|KeyboardArrowLeft|KeyboardArrowRight|NavigateBefore|NavigateNext|ChevronLeft|ChevronRight|HelpOutline|OpenInNew)\b""",
)
val AWT_CLIPBOARD_REFERENCE = Regex(
"""\bjava\.awt\.(?:Toolkit|datatransfer\.(?:DataFlavor|StringSelection))\b""",
)
val REDUNDANT_PUBLIC_VISIBILITY = Regex(
"""\bpublic\s+(?=(?:(?:actual|expect|data|sealed|enum|value|annotation|open|abstract|const|override|suspend|operator|infix|inline|tailrec|external|final|lateinit)\s+)*(?:class|interface|object|fun|val|var|typealias|constructor|companion)\b)""",
)
}
}
/** Prevents the Android companion product from regaining a second XML/View screen implementation. */
abstract class VerifyCompanionComposeUiOwnershipTask : DefaultTask() {
/** Android layout resources, which must remain empty for the companion product. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val layoutResources: ConfigurableFileCollection
/** Android product Kotlin sources checked for legacy View layout inflation. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val productSources: ConfigurableFileCollection
/** Shared companion Compose sources checked for a second feature-owned theme palette. */
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sharedUiSources: ConfigurableFileCollection
/** Enforces shared Compose ownership while leaving manifest/theme/icon XML available to Android packaging. */
@TaskAction
fun verify() {
val layoutViolations = layoutResources.files.sortedBy { it.path }.map { layout ->
"${layout.relativeTo(project.rootDir)} is an Android View layout"
}
val legacyTokens = listOf("setContentView(", "R.layout.")
val sourceViolations = productSources.files.sortedBy { it.path }.flatMap { source ->
source.readLines().mapIndexedNotNull { index, line ->
val token = legacyTokens.firstOrNull(line::contains) ?: return@mapIndexedNotNull null
"${source.relativeTo(project.rootDir)}:${index + 1} uses $token"
}
}
val companionPaletteTokens = listOf(
"darkColorScheme(",
"lightColorScheme(",
"Color(0x",
"Color.White",
"Color.Black",
"Color.Red",
"Color.Green",
"Color.Blue",
"Color.Yellow",
"Color.Gray",
)
val paletteViolations = sharedUiSources.files.sortedBy { it.path }.flatMap { source ->
source.readLines().mapIndexedNotNull { index, line ->
val token = companionPaletteTokens.firstOrNull(line::contains) ?: return@mapIndexedNotNull null
"${source.relativeTo(project.rootDir)}:${index + 1} owns palette token $token instead of using :ui:core"
}
}
val violations = layoutViolations + sourceViolations + paletteViolations
check(violations.isEmpty()) {
violations.joinToString(
prefix = "Android companion UI must be hosted from :ui:companion:sharedUi:\n",
separator = "\n",
)
}
}
}
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.androidMultiplatformLibrary) apply false
// in each subproject's classloader
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.room) apply false
alias(libs.plugins.kotlinSerialization) apply false
}
val allowedArchitectureDependencies = mapOf(
":application:desktop" to setOf(
":core:traffic",
":core:scripting",
":core:domain",
":core:connectivity",
":core:companion",
":core:identity",
":core:pairing",
),
":core:domain" to setOf(":core:logger", ":core:traffic", ":core:scripting"),
":core:scripting" to emptySet(),
":core:traffic" to emptySet(),
":core:identity" to emptySet(),
":core:pairing" to setOf(":core:identity"),
":core:connectivity" to emptySet(),
":core:companion" to setOf(
":core:connectivity",
":core:identity",
":core:pairing",
),
":application:companion" to setOf(
":core:companion",
":core:identity",
":core:logger",
":core:pairing",
),
":data:companion" to setOf(
":application:companion",
":core:companion",
":core:identity",
":core:logger",
":core:pairing",
),
":ui:companion:presentation" to setOf(
":application:companion",
":core:companion",
":core:logger",
),
":ui:companion:sharedUi" to setOf(
":core:companion",
":ui:core",
":ui:companion:presentation",
),
":connectivity:companion" to setOf(
":application:companion",
":core:companion",
":core:logger",
),
":products:companion:di" to setOf(
":application:companion",
":connectivity:companion",
":data:companion",
":ui:companion:presentation",
),
":products:companion:androidApp" to setOf(
":application:companion",
":connectivity:companion",
":core:companion",
":core:logger",
":data:companion",
":products:companion:di",
":ui:companion:presentation",
":ui:companion:sharedUi",
),
":products:companion:iosApp" to setOf(
":application:companion",
":connectivity:companion",
":core:companion",
":data:companion",
":products:companion:di",
":ui:core",
":ui:companion:presentation",
":ui:companion:sharedUi",
),
":connectivity:desktop" to setOf(
":application:desktop",
":core:companion",
":core:traffic",
":core:connectivity",
":core:identity",
":core:logger",
":core:pairing",
),
).mapValues { (_, paths) -> paths.sorted().joinToString(",") }
val moduleDocumentationPaths = subprojects.associate { module ->
module.path to module.file("MODULE.md").relativeTo(rootDir).invariantSeparatorsPath
}
val guardedBuildScriptFilesByModule = allowedArchitectureDependencies.keys.associateWith { modulePath ->
project(modulePath).buildFile.relativeTo(rootDir).invariantSeparatorsPath
}
val verifyModuleDocumentation by tasks.registering(VerifyModuleDocumentationTask::class) {
group = "verification"
description = "Verifies that every Gradle module has a root MODULE.md ownership contract."
repositoryDirectory.set(layout.projectDirectory)
documentationPaths.set(moduleDocumentationPaths)
documentationFiles.from(moduleDocumentationPaths.values.map(rootDir::resolve))
}
val verifyModuleBoundaries by tasks.registering(VerifyModuleBoundariesTask::class) {
group = "verification"
description = "Verifies dependency direction for the target architecture foundation modules."
repositoryDirectory.set(layout.projectDirectory)
this.allowedDependencies.set(allowedArchitectureDependencies)
guardedBuildScriptPaths.set(guardedBuildScriptFilesByModule)
guardedBuildScripts.from(guardedBuildScriptFilesByModule.values.map(rootDir::resolve))
}
val verifyUiRuntimeIsolation by tasks.registering(VerifyUiRuntimeIsolationTask::class) {
group = "verification"
description = "Verifies that UI production code does not depend on concrete KNet runtimes or storage."
productionSources.from(fileTree("ui") {
include("**/src/commonMain/**/*.kt", "**/src/jvmMain/**/*.kt")
exclude("**/build/**")
})
buildScripts.from(fileTree("ui") {
include("**/build.gradle.kts")
exclude("**/build/**")
})
allowedEngineImportPrefixes.set(
listOf(
"com.devuloopers.knet.engine.formatter.",
),
)
allowedEngineProjects.set(listOf(":engine:formatter"))
}
val verifyCompositionOwnership by tasks.registering(VerifyCompositionOwnershipTask::class) {
group = "verification"
description = "Verifies that Koin binding declarations live only in executable product roots."
productionSources.from(fileTree(".") {
include(
"**/src/main/**/*.kt",
"**/src/commonMain/**/*.kt",
"**/src/jvmMain/**/*.kt",
)
exclude("products/**", "**/build/**")
})
}
val verifyKotlinFirstSources by tasks.registering(VerifyKotlinFirstSourcesTask::class) {
group = "verification"
description = "Verifies Kotlin-first common and production source boundaries."
repositoryDirectory.set(layout.projectDirectory)
commonSources.from(fileTree(".") {
include("**/src/commonMain/**/*.kt")
exclude("**/build/**")
})
allKotlinSources.from(fileTree(".") {
include("**/*.kt")
exclude("**/build/**", ".gradle/**")
})
productionSources.from(fileTree(".") {
include(
"**/src/main/**/*.kt",
"**/src/commonMain/**/*.kt",
"**/src/androidMain/**/*.kt",
"**/src/jvmMain/**/*.kt",
)
exclude("**/build/**", "**/src/test/**", "**/src/commonTest/**", "**/src/jvmTest/**")
})
implicitApiSources.from(fileTree(".") {
include(
"core/domain/src/**/*.kt",
"core/http/src/**/*.kt",
"core/logger/src/**/*.kt",
"core/pairing/src/**/*.kt",
"core/serialization/src/**/*.kt",
"data/src/**/*.kt",
"data/desktop/src/**/*.kt",
"engine/src/**/*.kt",
"engine/*/src/**/*.kt",
"products/**/src/**/*.kt",
"storage/src/**/*.kt",
"testingServer/src/**/*.kt",
"ui/src/**/*.kt",
"ui/core/src/**/*.kt",
"ui/desktop/*/src/**/*.kt",
)
exclude(
"**/build/**",
"products/companion/di/src/**/*.kt",
"products/companion/iosPacketTunnel/src/**/*.kt",
)
})
allowedAwtClipboardPaths.set(
listOf("ui/core/src/jvmMain/kotlin/com/devuloopers/knet/ui/core/foundation/clipboard/ClipboardText.jvm.kt"),
)
}
val verifyCompanionComposeUiOwnership by tasks.registering(VerifyCompanionComposeUiOwnershipTask::class) {
group = "verification"
description = "Verifies that Android companion screens remain owned by shared Compose Multiplatform UI."
layoutResources.from(fileTree("products/companion/androidApp/src/main/res/layout") {
include("**/*.xml")
})
productSources.from(fileTree("products/companion/androidApp/src/main") {
include("**/*.kt")
exclude("**/build/**")
})
sharedUiSources.from(fileTree("ui/companion/sharedUi/src/commonMain") {
include("**/*.kt")
exclude("**/build/**")
})
}
val verifyArchitectureFoundation by tasks.registering {
group = "verification"
description = "Runs module ownership and target dependency-boundary checks."
dependsOn(
verifyModuleDocumentation,
verifyModuleBoundaries,
verifyUiRuntimeIsolation,
verifyCompositionOwnership,
verifyKotlinFirstSources,
verifyCompanionComposeUiOwnership,
)
}
/** Portable and Android companion gate. It is safe to run on Linux CI and never launches an app. */
tasks.register("companionSharedQualification") {
group = "verification"
description = "Runs companion models, workflows, persistence, presentation, Android adapters, and pairing crypto."
dependsOn(
verifyArchitectureFoundation,
":application:desktop:test",
":connectivity:desktop:jvmTest",
":core:companion:jvmTest",
":application:companion:jvmTest",
":data:companion:jvmTest",
":ui:companion:presentation:jvmTest",
":ui:companion:sharedUi:jvmTest",
":ui:core:jvmTest",
":ui:core:compileAndroidMain",
":connectivity:companion:testAndroidHostTest",
":data:companion:testAndroidHostTest",
":products:companion:di:testAndroidHostTest",
":data:companion:compileAndroidMain",
":ui:companion:presentation:compileAndroidMain",
":ui:companion:sharedUi:compileAndroidMain",
)
}
/** Kotlin/Native companion gate. It must run on macOS and never launches or signs an app. */
tasks.register("companionIosFoundationQualification") {
group = "verification"
description = "Compiles and tests companion iOS consumers for device and Simulator targets."
dependsOn(
verifyArchitectureFoundation,
":ui:core:compileKotlinIosSimulatorArm64",
":products:companion:di:iosSimulatorArm64Test",
":connectivity:companion:compileKotlinIosArm64",
":connectivity:companion:compileKotlinIosSimulatorArm64",
":connectivity:companion:iosSimulatorArm64Test",
":core:identity:compileKotlinIosSimulatorArm64",
":core:pairing:compileKotlinIosSimulatorArm64",
":core:connectivity:compileKotlinIosSimulatorArm64",
":core:companion:compileKotlinIosSimulatorArm64",
":application:companion:compileKotlinIosSimulatorArm64",
":data:companion:compileKotlinIosSimulatorArm64",
":ui:companion:presentation:compileKotlinIosSimulatorArm64",
":ui:companion:sharedUi:compileKotlinIosSimulatorArm64",
)
}
/** Complete companion foundation gate for macOS development and release qualification. */
tasks.register("companionFoundationQualification") {
group = "verification"
description = "Runs portable, Android, and iOS companion foundation qualification."
dependsOn(
"companionSharedQualification",
"companionIosFoundationQualification",
)
}
/** Installable Android companion product gate. It assembles the APK but never installs or launches it. */
tasks.register("companionAndroidProductQualification") {
group = "verification"
description = "Runs companion foundations, Android product composition tests/lint, and debug APK assembly."
dependsOn(
"companionSharedQualification",
":products:companion:androidApp:testDebugUnitTest",
":products:companion:androidApp:lintDebug",
":products:companion:androidApp:assembleDebug",
)
}
/** Installable iOS companion product gate. It links the simulator framework but never launches an app. */
tasks.register("companionIosProductQualification") {
group = "verification"
description = "Runs companion foundations and links the iOS product framework for the simulator."
dependsOn(
"companionFoundationQualification",
":products:companion:iosApp:linkDebugFrameworkIosSimulatorArm64",
)
}
/** Cross-module HTTP/2 qualification gate used locally and by the desktop operating-system CI matrix. */
tasks.register("http2Qualification") {
group = "verification"
description = "Runs HTTP/2 transport, capture, persistence, API Studio, Traffic, and protocol-lab tests."
dependsOn(
verifyArchitectureFoundation,
":core:http:jvmTest",
":core:traffic:jvmTest",
":engine:proxy:test",
":data:desktop:jvmTest",
":storage:jvmTest",
":testingServer:test",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:traffic:jvmTest",
":products:desktop:test",
)
}
/** Cross-module gRPC qualification gate. It never launches the desktop application. */
tasks.register("grpcQualification") {
group = "verification"
description = "Runs gRPC framing, persistence, breakpoints, API Studio, Traffic, and protocol-lab tests."
dependsOn(
verifyArchitectureFoundation,
":application:desktop:test",
":core:traffic:jvmTest",
":engine:grpc:test",
":engine:proxy:test",
":data:desktop:jvmTest",
":storage:jvmTest",
":testingServer:test",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:breakpointManager:jvmTest",
":ui:desktop:apiStudio:grpc:jvmTest",
":ui:desktop:traffic:jvmTest",
":products:desktop:test",
)
}
/** Cross-module WebSocket qualification gate. It never launches the desktop application. */
tasks.register("webSocketQualification") {
group = "verification"
description = "Runs WebSocket relay, framing, capture, breakpoints, API Studio, Traffic, and protocol-lab tests."
dependsOn(
verifyArchitectureFoundation,
":application:desktop:test",
":core:traffic:jvmTest",
":engine:proxy:test",
":engine:websocket:test",
":data:desktop:jvmTest",
":storage:jvmTest",
":testingServer:test",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:apiStudio:websocket:jvmTest",
":ui:desktop:breakpointManager:jvmTest",
":ui:desktop:traffic:jvmTest",
":products:desktop:test",
)
}
/** Cross-module GraphQL-over-WebSocket qualification gate. It never launches the desktop application. */
tasks.register("graphQLWebSocketQualification") {
group = "verification"
description = "Runs GraphQL WebSocket semantics, capture, breakpoints, API Studio, Traffic, and protocol-lab tests."
dependsOn(
verifyArchitectureFoundation,
":application:desktop:test",
":core:traffic:jvmTest",
":engine:proxy:test",
":engine:websocket:test",
":engine:graphqlWebSocket:test",
":data:desktop:jvmTest",
":storage:jvmTest",
":testingServer:test",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:apiStudio:websocket:jvmTest",
":ui:desktop:apiStudio:graphqlWebSocket:jvmTest",
":ui:desktop:breakpointManager:jvmTest",
":ui:desktop:traffic:jvmTest",
":products:desktop:test",
)
}
/** Cross-module Server-Sent Events qualification gate. It never launches the desktop application. */
tasks.register("sseQualification") {
group = "verification"
description = "Runs SSE codecs, capture, breakpoints, API Studio, Traffic, persistence, and protocol-lab tests."
dependsOn(
verifyArchitectureFoundation,
":application:desktop:test",
":core:http:jvmTest",
":core:traffic:jvmTest",
":engine:proxy:test",
":engine:sse:test",
":data:desktop:jvmTest",
":storage:jvmTest",
":testingServer:test",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:breakpointManager:jvmTest",
":ui:desktop:httpPanel:jvmTest",
":ui:desktop:traffic:jvmTest",
":products:desktop:test",
)
}
/** Explicit release-only SSE soak; defaults to three hours and is not part of ordinary CI. */
tasks.register("sseReleaseSoak") {
group = "verification"
description = "Runs the configurable long-duration SSE codec churn qualification."
dependsOn(":engine:sse:sseReleaseSoak")
}
/** Cross-module Network Conditions gate for proxy, presentation, persistence, and Android host policy. */
tasks.register("networkConditionsQualification") {
group = "verification"
description = "Runs Network Conditions domain, persistence, engine, UI, API Studio, Traffic, and Android-host tests."
dependsOn(
verifyArchitectureFoundation,
":core:domain:jvmTest",
":storage:jvmTest",
":data:desktop:jvmTest",
":application:desktop:test",
":engine:proxy:test",
":engine:protocol:test",
":engine:grpc:test",
":engine:websocket:test",
":engine:simulator:test",
":engine:graphqlWebSocket:test",
":ui:desktop:networkConditions:jvmTest",
":ui:desktop:apiStudio:jvmTest",
":ui:desktop:apiStudio:websocket:jvmTest",
":ui:desktop:apiStudio:graphqlWebSocket:jvmTest",
":ui:desktop:apiStudio:grpc:jvmTest",
":ui:desktop:traffic:jvmTest",
":ui:desktop:app:jvmTest",
":core:companion:jvmTest",
":application:companion:jvmTest",
":connectivity:companion:testAndroidHostTest",
":products:desktop:test",
)
}
/** Standard Phase 18 release gate; extended soak is invoked separately with its configured duration. */
tasks.register("phase18ReleaseGate") {
group = "verification"
description = "Runs architecture checks, all tests, and the packaged desktop distributable gate."
dependsOn(
verifyArchitectureFoundation,
subprojects.filter { module ->
module.buildFile.isFile && module.buildFile.readText().contains("plugins")
}.map { module -> "${module.path}:check" },
":products:desktop:createDistributable",
)
}
subprojects {
tasks.matching { task -> task.name == "check" }.configureEach {
dependsOn(rootProject.tasks.named("verifyArchitectureFoundation"))
}
}