此规则检查此 maven 会话(在 pom 文件甚至 settings.xml 中定义)是否包含指定的禁止存储库。
“requireNoRepositories”的目的是:检测 pom 和 pom 的 parent 是否包含 repositories 定义。指导用户使用正确的约定(不在 pom 文件中定义存储库)。所以它只分析当前的 pom 及其父 pom 文件。
但是“BannedRepositories”是不同的目的,它就像“BannedDependencies”。它将从 maven 会话上下文中检测被禁止的存储库,而不仅仅是 pom.xml 和父母。它试图避免滥用不正确的存储库。它将从当前的 Maven 会话上下文中检测被禁止的存储库。
例如,一家公司想要限制存储库的使用。但是不同的开发者可能会使用不同的 settings.xml。甚至他们项目的 pom 也定义了不同的存储库。对于这种情况,可以利用这个强制规则来禁止指定的存储库,甚至使用 allowedRepositories/allowedPluginRepositories 来禁止其他意外的存储库。
前任。http://repo1/xyz 是要被禁止的仓库。http://repo2/xyz 是现在要使用的存储库。
示例插件配置:
<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-repositories</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedRepositories>
<bannedRepositories>
<bannedRepository>http://repo1/*<bannedRepository>
</bannedRepositories>
<bannedPluginRepositories>
<bannedPluginRepository>http://repo1/*<bannedPluginRepository>
</bannedPluginRepositories>
<!-- for some cases, white list is more effective -->
<!--
<allowedRepositories>
<allowedRepository>http://repo2/*<allowedRepository>
</allowedRepositories>
<allowedPluginRepositories>
<allowedPluginRepository>http://repo2/*<allowedPluginRepository>
</allowedPluginRepositories>
-->
</bannedRepositories>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>