The Decycle Maven Plugin adds verification goals to the Maven build that check for package and slice cycles on the classes of a Maven project.
Requirements: Maven ≥ 3.3.1, Java ≥ 11
Add the decycle plugin to the build section of your pom.xml:
<build>
<plugins>
<plugin>
<groupId>de.obqo.decycle</groupId>
<artifactId>decycle-maven-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- see below -->
</configuration>
</plugin>
</plugins>
</build>The decycle plugin provides the goals decycle:check, decycle:checkMain, and decycle:checkTest.
The above base configuration will execute the goal decycle:check automatically in the verify phase of the maven lifecycle.
Decycle will check the main and the test classes separately, and it will create a dependency report for each check.
These reports can be found in the reporting directory,
i.e. typically the two reports are target/site/decycle/main.html and target/site/decycle/test.html.
If it detects violations (i.e. package cycles) then the build will fail by default
(however, this behavior can be adjusted, see ignoreFailures below in Configuration).
The two goals decycle:checkMain and decycle:checkTest are intended to be invoked as single goals
(e.g. via mvn decycle:checkMain). They will first compile the sources and perform the decycle check afterward.
They may be executed after fixing violations detected by decycle.
(Note: running decycle:check in contrast will not automatically recompile the sources.)
The execution of the decycle goals might be skipped by passing the following properties to maven
(e.g. via mvn verify -Ddecycle.skip):
decycle.skipwill skip decycle checks completelydecycle.skipMainwill skip the decycle check for themainclassesdecycle.skipTestwill skip the decycle check for thetestclasses
Setting the property decycle.ignoreFailures will ignore any failures detected by decycle
(but it will still generate the reports).
Within the configuration element of the plugin (see Installation above) the following parameters can be defined:
<configuration>
<including>org.example.includes.**, ...</including>
<excluding>org.example.excludes.**, ...</excluding>
<ignoring>
<dependency>
<from>org.examples.from.Example</from>
<to>org.examples.to.**</to>
</dependency>
</ignoring>
<slicings>
<slicing>
<name>module</name>
<patterns>org.example.{*}.**, ...</patterns>
<constraints>
<allow>a, b, ...</allow>
<allow-direct>
<any-of>x</any-of>
<any-of>y, z</any-of>
</allow-direct>
</constraints>
</slicing>
</slicings>
<ignoreFailures>false</ignoreFailures>
<skip>false</skip>
<skipMain>false</skipMain>
<skipTest>false</skipTest>
<skipReports>false</skipReports>
</configuration>-
includingdefines a comma separated list of patterns for the classes that should be included (default: all). -
excludingdefines a comma separated list of patterns for the classes that should be excluded (default: none). -
ignoringdefines a list of dependencies that should be ignored when checking cycle constraints on the analyzed classes (default none). This setting differs fromexcludingas the ignored dependency is not excluded from the dependency graph (i.e. it is present in the report). Each ignored dependency is represented by adependencyelement containingfromandtopatterns, both are optional:fromdefines the source of the dependency (default: all)todefines the target of the dependency (default: all)
-
slicingsdefines a list of slicings for the packages. Each slicing is represented by aslicingelement containingnameandpatternselements, both are required:namedefines the name of the slicingpatternsdefines a comma separated list of patterns, in which each pattern is either an unnamed pattern (containing curly braces for determining the slice) or a named pattern of the form pattern=slice (in which slice is the name of the slice and pattern is a simple pattern)constraintsenables the configuration of additional constraints on the defined slicesallowdefines a simple order constraintallow-directdefines a strict order constraint- both
allowandallow-directmay either contain a comma separated list of slice names, or they may contain onlyany-ofandone-ofelements (and no direct text content) any-ofcontains comma separated slices names with an unspecified slice orderone-ofcontains comma separated slices names that must not depend on each other
-
ignoreFailureswhether to allow the build to continue if there are constraint violations (default:false). This parameter can also be specified by defining the propertydecycle.ignoreFailures -
skipwhether to skip the execution of decycle (default:false). This parameter can also be specified by defining the propertydecycle.skip -
skipMainwhether to skip the execution of decycle on themainclasses (default:false). This parameter can also be specified by defining the propertydecycle.skipMain -
skipTestwhether to skip the execution of decycle on thetestclasses (default:false). This parameter can also be specified by defining the propertydecycle.skipTest -
skipReportswhether to skip the creation of the HTML reports (default:false). This parameter can also be specified by defining the propertydecycle.skipReports