此规则检查依赖关系,如果找到任何匹配的排除项,则失败。
此规则支持以下参数:
例如,要禁止除 xerces-api 之外的所有 xerces,您将排除“xerces”(groupId)并包括“xerces:xerces-api”
示例插件配置:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0</version> <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> <includes> <!--only 1.0 of badArtifact is allowed--> <include>org.apache.maven:badArtifact:1.0</include> </includes> </bannedDependencies> </rules> <fail>true</fail> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>
忽略传递依赖的示例插件配置:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>enforce-banned-dependencies</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <bannedDependencies> <excludes> <exclude>commons-lang:commons-lang</exclude> </excludes> <searchTransitive>false</searchTransitive> </bannedDependencies> </rules> <fail>true</fail> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>