Fork me on GitHub

Ban Circular Dependencies

This rule checks the dependencies and fails if the groupId:artifactId combination exists in the list of direct or transitive dependencies.

The following parameters are supported by this rule:

  • scopes - a list of scopes (e.g. test, provided) to include when scanning artifacts
  • ignoredScopes - a list of scopes (e.g. test, provided) to ignore when scanning artifacts
  • ignoreOptionals - a boolean, if true all dependencies which have <optional>true</optional> are ignored.
  • searchTransitive - a boolean, specify if transitive dependencies should be searched (default) or only look at direct dependencies.

Sample Plugin Configuration:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.4.1</version> <!-- find the latest version at http://maven.apache.org/plugins/maven-enforcer-plugin/ -->
        <executions>
          <execution>
            <id>enforce-ban-circular-dependencies</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <banCircularDependencies/>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.8.0</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Trademarks

Apache, Apache Maven, Maven and the Apache feather logo are trademarks of The Apache Software Foundation.