Skip to content

andrena/no-package-cycles-enforcer-rule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

no-package-cycles-enforcer-rule

Build Status

About

This Maven Enforcer Rule checks your project for package cycles. It fails the build if any package cycle is found, showing you the packages and classes involved in the cycle.

Usage

Add the following plugin to your POM:

<plugin>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0-M2</version>
    <dependencies>
        <dependency>
            <groupId>de.andrena.tools.nopackagecycles</groupId>
            <artifactId>no-package-cycles-enforcer-rule</artifactId>
            <version>1.0.9</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>enforce-no-package-cycles</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <phase>test</phase>
            <configuration>
                <rules>
                    <NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule" />
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

Including test classes

If you want to exclude tests from cycle checking, you can use the parameter includeTests which is set to true by default:

        ...
        <rules>
            <NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
                <includeTests>false</includeTests>
            </NoPackageCyclesRule>
        </rules>
        ...

Restricting scope

⚠️ Only use this, if there is no other way! Once there are exceptions, the connection between those excluded packages will grow stronger and stronger, without notice!

If you want to exclude packages or restrict check to certain packages only, you can use includedPackages or excludedPackages (although you really should not!):

        ...
        <rules>
            <NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
                <includedPackages>
                    <includedPackage>myapp.code.good</includedPackage>
                </includedPackages>
            </NoPackageCyclesRule>
        </rules>
        ...
        ...
        <rules>
            <NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
                <excludedPackages>
                    <excludedPackage>myapp.code.bad</excludedPackage>
                </excludedPackages>
            </NoPackageCyclesRule>
        </rules>
        ...

See also