此规则可用于强制您的 pom 文件中不存在 distributionManagement。
此规则支持以下参数:
示例插件配置:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>no-distribution-management-at-all</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banDistributionManagement/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
通常您应该只在有限的情况下定义distributionManagement 。如果您在公司环境中,通常只有在公司 pom 中定义distributionManagement并禁止在任何其他 pom 中使用才有意义。有时,允许例如在您的其他 pom 中定义站点存储库是有意义的,这可以通过使用banDistributionManagement规则来定义。对于这个用例,必须在您的公司 pom 文件中定义以下内容:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>no-distribution-management-at-all</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banDistributionManagement>
<allowSite>true</allowSite>
</banDistributionManagement>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
如果我们仔细研究可能的项目结构,您会发现以下情况,其中绿色箭头将显示我们当前的位置。
我们根本没有父级,也没有模块。这可能是我们正在创建公司 pom 文件或另一个简单的 Maven 项目的情况。所以 maven-enforcer-plugin 的定义在这个 pom 文件中。
因此,检查 pom 是否包含 distributionManagement 条目实际上没有任何意义。
我们有一个父母的项目。父级可能是一种包含 maven-enforcer-plugin 定义的公司 pom 文件。因此,在这种情况下,检查是否创建了 distributionManagement 条目是有意义的。
注意:目前无法检查父级是否不包含会改变情况的 maven-enforcer-plugin 的定义。

这种情况和之前的情况差不多。所以 banDistributionManagement 规则将检查 distributionManagement 条目。

如果我们没有父级,这意味着 maven-enforcer-plugin 的定义可能是在当前的 pom 文件中完成的,这意味着检查 distributionManagement 没有真正意义。

在这种情况下,我们有一个场景,模块 m1 有一个父p1,它可能包含 maven-enforcer-plugin 的定义,或者它的父级意味着检查 distributionManagement 条目。
