0

我在该项目中有一个 Parent maven 项目和 4 个模块:

在此处输入图像描述

现在我想放一些自定义规则,说不能有以字符串“master-”开头的项目版本或依赖版本。此规则将适用于所有依赖 eBill Software 的外部项目。

因此,我创建了一个名为 customRule 的新模块,其父模块又是 eBill Software。我遵循了编写自定义规则,并且我的规则类在新模块中。

模块customRule中CustomRule.java的相关部分:

 MavenProject project = (MavenProject) helper.evaluate( "${project}" );
 Set<Artifact> artifacts = project.getArtifacts();

            boolean containsInvalid = artifacts.stream()
                    .filter(item -> item.getVersion()
                    .startsWith("master-"))
                    .anyMatch(item -> true);

            if(containsInvalid) {
                this.shouldIfail = true;
            }

customRule 模块 pom.xml 的相关部分:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>enforce-no-master-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <myCustomRule implementation="org.apache.customRule.CustomRule">
                                    <shouldIfail>false</shouldIfail>
                                </myCustomRule>
                            </rules>
                        </configuration>

                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

现在我想在父模块 eBill Software 中访问这个自定义规则:

那么我应该在其 pom.xml 和外部项目的 pom.xml 中输入什么才能获得适用于依赖于 eBill Software 的所有外部项目的自定义规则。

4

0 回答 0