enforce custom rule in external projects

主宰稳场 提交于 2020-01-14 05:51:07

问题


I have one Parent maven project and 4 modules in that project:

Now I want to put some custom rule that says there can be no project versions or dependency versions that begin with the string "master-". This rule will be applicable to all the external projects that depends on eBill Software.

So I created a new module with name customRule whose parent is again eBill Software. I followed writing-a-custom-rule and my rule class is in new module.

Relevant part of CustomRule.java in module customRule:

 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;
            }

Relevant part of customRule module 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>

Now I want to access this custom rule in parent module eBill Software:

So what should I enter in its pom.xml and external project's pom.xml to be able to get the custom rule applicable to all the external projects that depends on eBill Software.

来源:https://stackoverflow.com/questions/48315914/enforce-custom-rule-in-external-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!