ArchRule
A single architecture rule evaluated against a ModuleDependencyGraph.
Implement this interface to create project-specific rules:
class NoAndroidInDomainRule : ArchRule {
override val id = "no-android-in-domain"
override val description = "Domain modules must not depend on Android libraries"
override val defaultSeverity = Severity.ERROR
override val plainLanguageExplanation =
"The domain layer must stay platform-agnostic so it can be shared via KMP."
override fun evaluate(graph: ModuleDependencyGraph): List<Violation> =
graph.edges
.filter { it.from.contains(":domain") }
.filter { graph.moduleByPath(it.to)?.type == ModuleType.ANDROID_LIBRARY }
.map { edge ->
Violation(
ruleId = id,
severity = defaultSeverity,
message = "${edge.from} depends on Android module ${edge.to}.",
source = "${edge.from} → ${edge.to}",
moduleHint = edge.from,
plainLanguageExplanation = plainLanguageExplanation,
)
}
}Content copied to clipboard