ForbiddenDependencySpec

Builds one predicate rule inside a forbid { } block: "modules matching from must not depend on modules matching to".

aalekh {
forbid {
from(":core:domain")
toModuleType(ModuleType.ANDROID_LIBRARY)
because("the domain layer stays platform-agnostic")
severity(Severity.ERROR) // default ERROR
}
forbid {
from(":feature:**")
to(":feature:**")
because("features must not depend on each other")
}
}

Each side is selected either by path glob (from / to) or by module type (fromModuleType / toModuleType). The spec serializes to a plain, configuration-cache-safe string; predicates are never captured as lambdas.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun apiOnly()

Restricts the rule to api dependencies only - an "API-leak" rule. The from module may still depend on to via implementation; it just may not re-export it onto its own consumers with api. Use it to stop a module widening its public surface, e.g. forbid { from(":core:public"); to(":core:internal"); apiOnly() }.

Link copied to clipboard
fun because(text: String)

Explains why the dependency is disallowed; shown in the violation message.

Link copied to clipboard
fun from(pattern: String)

Selects depending modules by Gradle path glob, e.g. ":feature:**".

Link copied to clipboard

Selects depending modules by ModuleType.

Link copied to clipboard
fun severity(level: Severity)

Severity for a match. ERROR (default) fails the build; WARNING only reports.

Link copied to clipboard
fun to(pattern: String)

Selects forbidden dependency targets by Gradle path glob.

Link copied to clipboard

Selects forbidden dependency targets by ModuleType.