Skip to content
A Gradle wrapper around ArchUnit, to easily share and enforce architecture rules across projects
Java Shell
Branch: master
Clone or download

ArchUnit Gradle plugin

Build Status


In our dev team at Gefa Bank GmbH, we really liked how ArchUnit Maven plugin was enabling teams to distribute rules across projects. Only "problem" was that we're using Gradle, not Maven. So we decided to write an equivalent plugin for Gradle.

What is it, and how does it work ?

ArchUnit-Gradle-plugin is a wrapper around Arch-Unit-Build-Plugin-Core, which itself is a wrapper around ArchUnit, that enables you to easily make sure all your projects follow the same architecture rules.

Using a plugin brings a way to manage the rules through build configuration and to easily share and enforce architecture rules across projects.

To use the plugin, your build.gradle require these changes:

  1. Declare the dependency to the plugin :
   buildscript {
       dependencies {
           classpath "com.societegenerale.commons:arch-unit-gradle-plugin:1.0.3"
       repositories {
  1. Apply the java plugin and the ArchUnitGradlePlugin, then configure it:
    allprojects {
        apply plugin: 'java'
        apply plugin: 'com.societegenerale.commons.plugin.gradle.ArchUnitGradlePlugin'

                  configurableRules=[configurableRule("com.tngtech.archunit.library.GeneralCodingRules", applyOn("","main") )]
  1. Build your project with gradlew clean build : if some of your code is not compliant with the rules defined, the build will fail, pointing you to the rule(s) and the class(es) that are violating it.

Adding new rules

All rules referenced in the configuration have to be available in the classpath. Therefore, you have 2 solutions :

  • package your rule into a custom jar, add a dependency to this jar (probably with test scope) and declare the rule in the config
  • Propose your rule through a PullRequest to Arch-Unit-Build-Plugin-Core : if it's accepted, it will be part of the next release and usable by everyone.

Releasing a new version of the plugin

(to publish in local repo during tests, use gradlew -Dmaven.repo.local=.m2/repository publishToMavenLocal)

You can’t perform that action at this time.