TNG/ArchUnit


A Java architecture test library, to specify and assert architecture rules in plain Java http://archunit.org

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.TNG:ArchUnit:v0.4.0'
	}
	dependencies {
		implementation("com.github.TNG:ArchUnit:v0.4.0")
	}
	<dependency>
	    <groupId>com.github.TNG</groupId>
	    <artifactId>ArchUnit</artifactId>
	    <version>v0.4.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.TNG" % "ArchUnit" % "v0.4.0"
        
        

                            
    :dependencies [[com.github.TNG/ArchUnit "v0.4.0"]]
        
        

Readme


CI Maven Central License

<img src="logo/ArchUnit-Logo.png" height="64" alt="ArchUnit">

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between packages and classes, layers and slices, check for cyclic dependencies and more. It does so by analyzing given Java bytecode, importing all classes into a Java code structure. ArchUnit's main focus is to automatically test architecture and coding rules, using any plain Java unit testing framework.

An Example

Add the Maven Central dependency to your project

Gradle
testImplementation 'com.tngtech.archunit:archunit:1.4.0'
Maven
<dependency>
    <groupId>com.tngtech.archunit</groupId>
    <artifactId>archunit</artifactId>
    <version>1.4.0</version>
    <scope>test</scope>
</dependency>

Create a test

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;

public class MyArchitectureTest {
    @Test
    public void some_architecture_rule() {
        JavaClasses importedClasses = new ClassFileImporter().importPackages("com.myapp");
    
        ArchRule rule = classes()... // see next section
    
        rule.check(importedClasses);
    }
}

Let the API guide you

ArchUnit Fluent API

Where to look next

For further information, check out the user guide at http://archunit.org or test examples for the current release at ArchUnit Examples.

License

ArchUnit is published under the Apache License 2.0, see http://www.apache.org/licenses/LICENSE-2.0 for details.

It redistributes some third party libraries:

  • ASM (http://asm.ow2.org), under BSD Licence
  • Google Guava (https://github.com/google/guava), under Apache License 2.0

All licenses for ArchUnit and redistributed libraries can be found within the licenses folder.