Clean Architecture Gradle Plugin

Background

These days a large part of Software Engineering is about managing complexity due to our programs having grown large in size, often performing many tasks and being increasingly parallel. In OOP design principles like SOLID have become popular to make designs more understandable, flexible, and maintainable. On a more granular level it is a common practice to structure programs and systems into abstraction layers such that reasoning about one part of the structure becomes easier for humans.

The following picture illustrates a typical 3-layer architecture structure.

3 layers

Projects using Gradle as build system can either

  1. map the layers into individual projects enforcing the dependency via project dependency or

  2. use a single project and map the layers into multiple package namespaces

Option 1. has the drawback that each layer needs to provide a publicly accessible interface that can also be used from anywhere and 2. has the drawback that the convention to respect the layer dependency direction is easily violated during the evolution of the code base.

The Plugin

This Gradle plugin uses Code Lint Rules to enforce the layer dependency convention when using a single project containing multiple abstraction layers.

Usage in a build.gradle.kts file

plugins {
  id("net.bonzani.clean-architecture") version "1.0.0"
}

The plugin enforces imports to be only in one direction e.g., presentation importing from business-logic and data-access and business-logic from data-access, but not the other way around.

These rules are added checked as part of the gradle lint task.