A lightweight Gradle plugin for enforcing package dependency rules in Android & Kotlin projects. Define which packages can import from others within your project and enforce it automatically.
Structural is intended to be a quick way to enforce a modular architecture when other tools are not preferred or available. However, it can also be used for other purposes such as just forbidding one local package from importing from another.
plugins {
id("com.adrianczuczka.structural") version "[version]"
}
repositories {
mavenCentral()
}
Structural requires a YAML file to understand the intended package structure. First, create a YAML file in your project. You can link it like this:
structural {
config = "./structural.yml"
}
If you omit this, it will look for a structural.yml
file by default in the root directory.
In your YAML file, there should be two main sections: packages
and rules
. packages
should be a
list of all package names that Structural should check. For example, if you follow MVVM and Clean
Architecture rules, your list could look like this:
packages:
- local
- remote
- data
- domain
- ui
These are all the packages that will have rules related to which ones can import from which others.
The rules
section should specify the rules which govern the package structure. There are two ways
to write these rules. You can either use arrows to specify the relationships, like this:
rules:
- data <- domain -> ui
- local <- data
- remote <- data
This means that
- The
data
andui
folders can import from thedomain
folder, but not vice versa - The
local
andremote
folders can import from thedata
folder, but not vice versa
The same rules can also be written like this:
rules:
# YAML lists are supported
? [ui, data]
: - domain
? [local, remote]
: - data
# Also works
ui:
- domain
data:
- domain
local:
- data
remote:
- data
To check the validity of your module's folder structure, run:
./gradlew structuralCheck
An example result will look like this:
This plugin is currently compatible up to Kotlin 2.0.0.