rweisleder / archunit-spring

Library providing predefined ArchUnit rules for Spring applications
Apache License 2.0
75 stars 2 forks source link

= ArchUnit Spring Integration

The ArchUnit Spring Integration provides predefined https://github.com/TNG/ArchUnit[ArchUnit] rules for https://spring.io/projects[Spring] applications.

image:https://maven-badges.herokuapp.com/maven-central/de.rweisleder/archunit-spring/badge.svg[link="https://central.sonatype.com/artifact/de.rweisleder/archunit-spring", title="Maven Central"] image:https://javadoc.io/badge2/de.rweisleder/archunit-spring/javadoc.svg[link="https://javadoc.io/doc/de.rweisleder/archunit-spring", title="Javadoc"] image:https://img.shields.io/github/license/rweisleder/archunit-spring.svg[link="https://github.com/rweisleder/archunit-spring/blob/main/LICENSE", title="License"]

== Usage

[source,xml]

de.rweisleder archunit-spring 1.0.0 test

The library expects that the required dependencies for Spring and ArchUnit are already declared.

== Examples

Given the following class: [source,java]

@RestController class DemoRestController {

@GetMapping("/hello")
String hello() {
    return "Hello World";
}

}

You can write architecture rules like this:

[source,java]

import static de.rweisleder.archunit.spring.SpringAnnotationPredicates.springAnnotatedWith;

methods() // "that are annotated with @RequestMapping" (or @GetMapping, @PostMapping etc.) .that(are(springAnnotatedWith(RequestMapping.class))) // "should be declared in classes that are annotated with @Controller" (or @RestController etc.) .should().beDeclaredInClassesThat(are(springAnnotatedWith(Controller.class)));

== User Guide

Please refer to the complete documentation https://github.com/rweisleder/archunit-spring/blob/main/src/main/docs/userguide.adoc[here] for detailed information.