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.skip
will skip decycle checks completelydecycle.skipMain
will skip the decycle check for themain
classesdecycle.skipTest
will skip the decycle check for thetest
classes
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>
-
including
defines a comma separated list of patterns for the classes that should be included (default: all). -
excluding
defines a comma separated list of patterns for the classes that should be excluded (default: none). -
ignoring
defines a list of dependencies that should be ignored when checking cycle constraints on the analyzed classes (default none). This setting differs fromexcluding
as the ignored dependency is not excluded from the dependency graph (i.e. it is present in the report). Each ignored dependency is represented by adependency
element containingfrom
andto
patterns, both are optional:from
defines the source of the dependency (default: all)to
defines the target of the dependency (default: all)
-
slicings
defines a list of slicings for the packages. Each slicing is represented by aslicing
element containingname
andpatterns
elements, both are required:name
defines the name of the slicingpatterns
defines 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)constraints
enables the configuration of additional constraints on the defined slicesallow
defines a simple order constraintallow-direct
defines a strict order constraint- both
allow
andallow-direct
may either contain a comma separated list of slice names, or they may contain onlyany-of
andone-of
elements (and no direct text content) any-of
contains comma separated slices names with an unspecified slice orderone-of
contains comma separated slices names that must not depend on each other
-
ignoreFailures
whether to allow the build to continue if there are constraint violations (default:false
). This parameter can also be specified by defining the propertydecycle.ignoreFailures
-
skip
whether to skip the execution of decycle (default:false
). This parameter can also be specified by defining the propertydecycle.skip
-
skipMain
whether to skip the execution of decycle on themain
classes (default:false
). This parameter can also be specified by defining the propertydecycle.skipMain
-
skipTest
whether to skip the execution of decycle on thetest
classes (default:false
). This parameter can also be specified by defining the propertydecycle.skipTest
-
skipReports
whether to skip the creation of the HTML reports (default:false
). This parameter can also be specified by defining the propertydecycle.skipReports