Taikai extends the capabilities of the popular ArchUnit library by offering a comprehensive suite of predefined rules tailored for various technologies. It simplifies the enforcement of architectural constraints and best practices in your codebase, ensuring consistency and quality across your projects.
Add Taikai as a dependency in your pom.xml
:
<dependency>
<groupId>com.enofex</groupId>
<artifactId>taikai</artifactId>
<version>${taikai.version}</version>
<scope>test</scope>
</dependency>
Replace ${taikai.version}
with the appropriate version defined in your project. Ensure that the required dependencies like ArchUnit are already declared.
Here's an example demonstrating the usage of Taikai with JUnit 5. Customize rules as needed using TaikaiRule.of()
.
@Test
void shouldFulfillConstraints() {
Taikai.builder()
.namespace("com.enofex.taikai")
.java(java -> java
.noUsageOfDeprecatedAPIs()
.methodsShouldNotDeclareGenericExceptions()
.utilityClassesShouldBeFinalAndHavePrivateConstructor()
.imports(imports -> imports
.shouldHaveNoCycles()
.shouldNotImport("..shaded..")
.shouldNotImport("org.junit.."))
.naming(naming -> naming
.classesShouldNotMatch(".*Impl")
.methodsShouldNotMatch("foo")
.fieldsShouldNotMatch("bar")
.fieldsShouldMatch("com.awesome.Foo", "foo")
.constantsShouldFollowConventions()
.interfacesShouldNotHavePrefixI()))
.logging(logging -> logging
.loggersShouldFollowConventions(Logger.class, "logger", EnumSet.of(PRIVATE, FINAL)))
.test(test -> test
.junit5(junit5 -> junit5
931E
.classesShouldNotBeAnnotatedWithDisabled()
.methodsShouldNotBeAnnotatedWithDisabled()))
.spring(spring -> spring
.noAutowiredFields()
.boot(boot -> boot
.springBootApplicationShouldBeIn("com.enofex.taikai"))
.configurations(configuration -> configuration
.namesShouldEndWithConfiguration())
.controllers(controllers -> controllers
.shouldBeAnnotatedWithRestController()
.namesShouldEndWithController()
.shouldNotDependOnOtherControllers()
.shouldBePackagePrivate())
.services(services -> services
.shouldBeAnnotatedWithService()
.shouldNotDependOnControllers()
.namesShouldEndWithService())
.repositories(repositories -> repositories
.shouldBeAnnotatedWithRepository()
.shouldNotDependOnServices()
.namesShouldEndWithRepository()))
.addRule(TaikaiRule.of(...)) // Add custom ArchUnit rule here
.build()
.check();
}
Explore the complete documentation for comprehensive information on all available rules.
Interested in contributing? Check out our Contribution Guidelines for details on how to get involved. Note, that we expect everyone to follow the Code of Conduct.
- Git
- Java 21 or higher
Clone the repository
git clone git@github.com:enofex/taikai.git
cd taikai
To compile, test, and build
./mvnw clean package -B