### Install Spring Modulith Module ArchUnit Dependencies
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Add the necessary `spring-modulith-module-archunit` and `spring-modulith-module-archunit-starter` dependencies to your project. These libraries are for testing and require Java 17+ and Spring Boot 3+.
```Gradle
dependencies {
testImplementation("dev.clutcher:spring-modulith-module-archunit:1.0.0")
testImplementation("dev.clutcher:spring-modulith-module-archunit-starter:1.0.0")
}
```
```Maven
dev.clutcher
spring-modulith-module-archunit
1.0.0
test
dev.clutcher
spring-modulith-module-archunit-starter
1.0.0
test
```
--------------------------------
### Example Hexagonal Architecture Package Structure
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Demonstrates the recommended directory and package layout for a module adhering to hexagonal architecture principles, distinguishing between application core (app) and external adapters (in, out).
```text
some-module/
├─ app/
│ ├─ api/ # Driving ports (primary ports)
│ │ └─ ApiForDoingSomething.java
│ ├─ domain/
│ │ ├─ services/ # Application services
│ │ │ └─ DoingSomethingService.java
│ │ └─ model/ # Domain model
│ │ └─ Object.java
│ └─ spi/ # Driven ports (secondary ports)
│ └─ SomeRepository.java
├─ in/ # Driving adapters (primary adapters)
│ └─ rest/
│ └─ SomeRestController.java
└─ out/ # Driven adapters (secondary adapters)
└─ db/
└─ SomeRepositoryUsingMysql.java
another-module/
├─ app/
│ ├─ api/
│ │ └─ ApiForDoingSomethingElse.java
```
--------------------------------
### Verify Spring Modulith Modules with ArchUnit in Spring Boot Tests
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Set up a Spring Boot test class to automatically verify module architecture. This example uses `ApplicationModules.of()` to discover modules and `ApiForModuleArchitectureVerification.verifyAllModules()` to apply ArchUnit rules.
```Java
import dev.clutcher.modulith.archunit.verifier.app.api.ApiForModuleArchitectureVerification;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.modulith.core.ApplicationModules;
@SpringBootTest
class ApplicationModulesTests {
@Autowired
private ApiForModuleArchitectureVerification moduleArchitectureVerification;
@Test
void verifyModules() {
ApplicationModules applicationModules = ApplicationModules.of(Application.class);
applicationModules.forEach(System.out::println);
applicationModules.verify();
moduleArchitectureVerification.verifyAllModules(applicationModules);
}
}
```
--------------------------------
### Spring Bean Definitions for spring-modulith-module-archunit-starter
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Details the Spring beans created by `VerificationStrategyAutoconfiguration` in the `spring-modulith-module-archunit-starter` project, including their names, purposes, and dependencies for hexagonal architecture verification.
```APIDOC
VerificationStrategyAutoconfiguration creates beans:
1. HexagonalPackageSettingsUsingSpringProperties
- Bean name: hexagonalArchitectureVerificationProperties
- Purpose: Holds hexagonal architecture configuration settings
- Dependencies: none
2. HexagonalArchRuleCreationService
- Bean name: hexagonalArchRuleCreationService
- Purpose: Creates service to provide set of rules for hexagonal architecture
- Dependencies: HexagonalArchitectureSettings
3. ModuleArchitectureVerificationService
- Bean name: applicationModulesArchitectureVerifier
- Purpose: Verifies module architecture against defined rules
- Dependencies: List (requires list as modules can be implemented using different architectures)
```
--------------------------------
### API for Module Architecture Verification in spring-modulith-module-archunit
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Outlines the primary components responsible for verifying module architecture against defined rules within the spring-modulith-module-archunit project.
```APIDOC
Architecture Rule Verification:
- ApiForModuleArchitectureVerification: Main entry point to verify module architecture
- ModuleArchitectureVerificationService: Service implementation for verifying module architecture
```
--------------------------------
### API for Architecture Rule Creation in spring-modulith-module-archunit
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Defines the main entry points and services for creating and customizing ArchUnit rules within the spring-modulith-module-archunit project, including support for hexagonal architecture.
```APIDOC
Architecture Rule Creation:
- ApiForArchRuleCreation: Main entry point for creating ArchUnit rules
- ApiForCustomizingArchRuleCreation: Main entry point for customizing existing instances of ApiForArchRuleCreation using DelegatingArchRuleCreationService
- HexagonalArchRuleCreationService: Service for creating hexagonal architecture rule sets
- DelegatingArchRuleCreationService: Service implementation to be used for custom rules creation
- HexagonalArchitectureRulesLibrary: Library of predefined rules for hexagonal architecture
```
--------------------------------
### Configure Custom ArchUnit Rules for Spring Modulith Modules
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Define custom architecture validation rules programmatically using `ApiForCustomizingArchRuleCreation`. This allows for flexible configuration of layer rules or extending existing rule sets like `HexagonalArchRuleCreationService`.
```Java
@Configuration
public class ModuleArchitectureRulesConfiguration {
@Bean
public ApiForArchRuleCreation customArchRuleCreation() {
return ApiForCustomizingArchRuleCreation
.forApplicabilityChecker((m, allClassesRelatedToModule) -> true)
.withLayerRule((m) -> null)
.create();
}
@Bean
public ApiForArchRuleCreation customArchRuleCreation() {
HexagonalArchRuleCreationService defaultHexagonalRuleCreationService = new HexagonalArchRuleCreationService(
new HexagonalPackageSettingsUsingSpringProperties()
);
return ApiForCustomizingArchRuleCreation
.forExistingArchRuleCreation(defaultHexagonalRuleCreationService)
.withPackageStructureRule((m) -> null)
.create();
}
}
```
--------------------------------
### Configure Hexagonal Architecture Layer Packages in Spring
Source: https://github.com/clutcher/spring-modulith-module-archunit/blob/main/README.md
Spring properties used to customize the package patterns for different hexagonal architecture layers, such as driving/driven ports and adapters, within a Spring Modulith application.
```properties
dev.clutcher.modulith.archunit.rules.hexagonal.package.port.driving = .api..
dev.clutcher.modulith.archunit.rules.hexagonal.package.port.driven = .spi..
dev.clutcher.modulith.archunit.rules.hexagonal.package.adapter.driving = .in..
dev.clutcher.modulith.archunit.rules.hexagonal.package.adapter.driven = .out..
dev.clutcher.modulith.archunit.rules.hexagonal.package.application.root = .app
dev.clutcher.modulith.archunit.rules.hexagonal.package.application.services = .domain.services..
dev.clutcher.modulith.archunit.rules.hexagonal.package.application.configuration = .config..
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.