Banned Dependencies

This rule checks the dependencies and fails if any of the matching excludes are found.

The following parameters are supported by this rule:

  • searchTransitive - if transitive dependencies should be checked.
  • excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version] where artifactId and version are optional. Wildcards may be used to replace an entire section. Examples:
    • org.apache.maven
    • org.apache.maven:badArtifact
    • org.apache.maven:artifact:badVersion
    • org.apache.maven:*:1.2
  • message - an optional message to the user if the rule fails.

Sample Plugin Configuration:

<project>
  [...]
  <build>
   <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-banned-dependencies</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <bannedDependencies>
                   <excludes>
                      <exclude>org.apache.maven</exclude>
                      <exclude>org.apache.maven:badArtifact</exclude>
                      <exclude>*:badArtifact</exclude>
                   </excludes>
                </bannedDependencies>
             </rules>  
            <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>