ArchUnit Gradle Plugin

A Gradle plugin to run packaged ArchUnit rules

License

License

Apache 2
Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.societegenerale.commons
ArtifactId

ArtifactId

arch-unit-gradle-plugin
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

ArchUnit Gradle Plugin
A Gradle plugin to run packaged ArchUnit rules
Project URL

Project URL

https://github.com/societe-generale/arch-unit-gradle-plugin
Source Code Management

Source Code Management

https://github.com/societe-generale/arch-unit-gradle-plugin

Download arch-unit-gradle-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/com.societegenerale.commons/arch-unit-gradle-plugin/ -->
<dependency>
    <groupId>com.societegenerale.commons</groupId>
    <artifactId>arch-unit-gradle-plugin</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.societegenerale.commons/arch-unit-gradle-plugin/
implementation 'com.societegenerale.commons:arch-unit-gradle-plugin:1.0.4'
// https://jarcasting.com/artifacts/com.societegenerale.commons/arch-unit-gradle-plugin/
implementation ("com.societegenerale.commons:arch-unit-gradle-plugin:1.0.4")
'com.societegenerale.commons:arch-unit-gradle-plugin:jar:1.0.4'
<dependency org="com.societegenerale.commons" name="arch-unit-gradle-plugin" rev="1.0.4">
  <artifact name="arch-unit-gradle-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.societegenerale.commons', module='arch-unit-gradle-plugin', version='1.0.4')
)
libraryDependencies += "com.societegenerale.commons" % "arch-unit-gradle-plugin" % "1.0.4"
[com.societegenerale.commons/arch-unit-gradle-plugin "1.0.4"]

Dependencies

runtime (1)

Group / Artifact Type Version
com.societegenerale.commons : arch-unit-build-plugin-core jar 2.4.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

ArchUnit Gradle plugin

Build Status Gradle plugin

Context

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.

Latest version of the plugin is available on https://plugins.gradle.org/plugin/com.societegenerale.commons.arch-unit-gradle-plugin

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:2.6.1"
       }
       repositories {
           mavenCentral()
       }
   }
  1. Apply the java plugin and the ArchUnitGradlePlugin, then configure it:
    allprojects {
    
        apply plugin: 'java'
        apply plugin: 'com.societegenerale.commons.plugin.gradle.ArchUnitGradlePlugin'
    
        archUnit{
        
                 excludedPaths=["some/package"]

                  preConfiguredRules=["com.societegenerale.commons.plugin.rules.NoInjectedFieldTest",
                            "com.societegenerale.commons.plugin.rules.NoAutowiredFieldTest",
                            "com.societegenerale.commons.plugin.rules.NoTestIgnoreWithoutCommentRuleTest",
                            "com.societegenerale.commons.plugin.rules.NoPrefixForInterfacesRuleTest",
                            "com.societegenerale.commons.plugin.rules.NoPowerMockRuleTest",
                            "com.societegenerale.commons.plugin.rules.NoJodaTimeRuleTest",
                            "com.societegenerale.commons.plugin.rules.NoJunitAssertRuleTest",
                            "com.societegenerale.commons.plugin.rules.HexagonalArchitectureTest",
                            "com.societegenerale.commons.plugin.rules.DontReturnNullCollectionTest",
                            "com.societegenerale.commons.plugin.rules.StringFieldsThatAreActuallyDatesRuleTest"
                                    ]

                  configurableRules=[configurableRule("com.tngtech.archunit.library.GeneralCodingRules", applyOn("com.my.project","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

com.societegenerale.commons

Société Générale

Versions

Version
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0